PureBasic 6.00 released !
Re: PureBasic 6.00 Beta 9 released !
Thanks for the http timeout option. Convenient.
Re: PureBasic 6.00 Beta 9 released !
Yes,Fred wrote: Sat Jun 04, 2022 7:27 am I thought the timeout would be used more often than headers, hence the switch, but i could put it last.
I think it's important to add the new parameter at the end so that we don't have to modify all the old code that uses ReceiveHTTPFile(), ReceiveHTTPMemory(), HTTPRequest(), HTTPRequestMemory().
We could propose a default value to avoid having to specify a complete map for Headers() (i.e #Default_Header$ ? or 0 ?)
- RichAlgeni
- Addict

- Posts: 935
- Joined: Wed Sep 22, 2010 1:50 am
- Location: Bradenton, FL
Re: PureBasic 6.00 Beta 9 released !
+1Marc56us wrote: Sat Jun 04, 2022 1:33 pm I think it's important to add the new parameter at the end so that we don't have to modify all the old code that uses ReceiveHTTPFile(), ReceiveHTTPMemory(), HTTPRequest(), HTTPRequestMemory().
We could propose a default value to avoid having to specify a complete map for Headers() (i.e #Default_Header$ ? or 0 ?)
Re: PureBasic 6.00 Beta 9 released !
You can't have a default map as constant yet, so you will have to pass an empty map. I will switch the param for the next beta
- DeanH
- Enthusiast

- Posts: 281
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Re: PureBasic 6.00 Beta 9 released !
After giving it some thought I feel putting the timeout before the header parameter, as Fred as done, may be better. The timeout is more likely to be used more often than the header map. Putting the optional timeout at the end breaks less existing code but causes a bother for those who would like to use it but not need the headers.
I use a trick in Windows to identify any bit of source code that needs investigation. I open a command window, navigate to the correct folder, then use the Find command. Example: Find /I "httprequest" *.pb* > temp.txt. When it finishes I then do Notepad temp.txt to see the results. I have this in a batch file. I'm not sure if or how it can be done in Mac and Linux but it saves a lot of time tracking something down that needs to be changed.
As an alternative to putting the timeout at the end, what about having a separate function called before HttpRequest? Maybe HttpTimeout( arg )? Or immediately after?
I use a trick in Windows to identify any bit of source code that needs investigation. I open a command window, navigate to the correct folder, then use the Find command. Example: Find /I "httprequest" *.pb* > temp.txt. When it finishes I then do Notepad temp.txt to see the results. I have this in a batch file. I'm not sure if or how it can be done in Mac and Linux but it saves a lot of time tracking something down that needs to be changed.
As an alternative to putting the timeout at the end, what about having a separate function called before HttpRequest? Maybe HttpTimeout( arg )? Or immediately after?
Re: PureBasic 6.00 Beta 9 released !
.
Last edited by BarryG on Sun Jun 05, 2022 5:23 am, edited 1 time in total.
Re: PureBasic 6.00 Beta 9 released !
The same can be said for those who never have a need to change the timeout but always use the headers... like myself.DeanH wrote: Sun Jun 05, 2022 12:51 am Putting the optional timeout at the end breaks less existing code but causes a bother for those who would like to use it but not need the headers.
Have you tried "Find in Files" under "Edit" in the IDE? It will show the exact line# in every file and you can double click on it to load that line into the IDE to view.I use a trick in Windows to identify any bit of source code that needs investigation. I open a command window, navigate to the correct folder, then use the Find command. Example: Find /I "httprequest" *.pb* > temp.txt
Maybe you could demonstrate a macro that allows you to move the Header() part around?BarryG wrote:And a simple macro at the start of a source will reverse the order to not break any existing code.
Re: PureBasic 6.00 Beta 9 released !
My bad; I didn't realise the parameters used a map. But macros support maps, so it should still be possible?Paul wrote: Sun Jun 05, 2022 3:53 amMaybe you could demonstrate a macro that allows you to move the Header() part around?
Re: PureBasic 6.00 Beta 9 released !
As Fred said, a Map can be empty.
It will therefore be simple: only one line to add.
In addition we can remove InitNetwork() (which troubled beginners because its absence did not cause a specific error message)
The example of help, updated for B9.
So with the Timout at the end (next beta), only the new codes will be affected, and only one line to add.
PS. Tested: Even with an empty map, the server receives "Mozilla/5.0 Gecko/41.0 Firefox/41.0" as HTTP_USER_AGENT, so add Header$("User-Agent") if server ask for recent version.
It will therefore be simple: only one line to add.
In addition we can remove InitNetwork() (which troubled beginners because its absence did not cause a specific error message)
The example of help, updated for B9.
Code: Select all
; PB 6.00 B9
; InitNetwork() ; Not needed now :-)
NewMap Header$()
; Header$("Content-Type") = "plaintext"
; Header$("User-Agent") = "Firefox 54.0" ; Error in Help: Must be User-Agent not UserAgent
HttpRequest = HTTPRequest(#PB_HTTP_Get, "https://www.google.com", "", 0, 30000, Header$())
If HttpRequest
Debug "StatusCode: " + HTTPInfo(HTTPRequest, #PB_HTTP_StatusCode)
Debug "Response: " + HTTPInfo(HTTPRequest, #PB_HTTP_Response)
FinishHTTP(HTTPRequest)
Else
Debug "Request creation failed"
EndIfPS. Tested: Even with an empty map, the server receives "Mozilla/5.0 Gecko/41.0 Firefox/41.0" as HTTP_USER_AGENT, so add Header$("User-Agent") if server ask for recent version.
Re: PureBasic 6.00 Beta 9 released !
I'm still curious on this one... current command we put zero for flag if we don't need the flag and need the header (although for consistency it would make more sense to use #PB_Ignore)Paul wrote: Fri Jun 03, 2022 6:09 pm Anyway, if one wants to use the default timeout, can you simply put 0 for the default of 30 or do you have to put 30 or 30000 ?
Code: Select all
HTTPRequest(#PB_HTTP_Get, url$, "", 0, Header$())What do we use for default timeout? Will this use default of 30 seconds by putting 0 or would there be no timeout?
Code: Select all
HTTPRequest(#PB_HTTP_Get, url$, "", 0, 0, Header$())Re: PureBasic 6.00 Beta 9 released !
As mentioned earlier in this thread, why not just add a new generic function HttpTimeout() that sets the timeout for all subsequent calls to all the different Http...() functions, for the current thread? This will not break existing code and is similar to the already existing HttpProxy()-function.
As you walk on by, Will you call my name? Or will you walk away?
Re: PureBasic 6.00 Beta 9 released !
+1wayne-c wrote: Sun Jun 05, 2022 4:12 pm As mentioned earlier in this thread, why not just add a new generic function HttpTimeout() that sets the timeout for all subsequent calls to all the different Http...() functions, for the current thread? This will not break existing code and is similar to the already existing HttpProxy()-function.
Very good solution!
Re: PureBasic 6.00 Beta 9 released !
But isnt some cases where timeout would be better to have diffirent teout in different functions ?
I.e. receivehttpfile may have bigger timeout than httprequest
Since simple requests are usyally queries and small data
While files are bigger
For example an applications that send requests to receive files
(Http downloader) send a tiny request ,while it may receive huge file
I.e. receivehttpfile may have bigger timeout than httprequest
Since simple requests are usyally queries and small data
While files are bigger
For example an applications that send requests to receive files
(Http downloader) send a tiny request ,while it may receive huge file
Christos
Re: PureBasic 6.00 Beta 9 released !
Yes,plouf wrote: Sun Jun 05, 2022 5:18 pm But isnt some cases where timeout would be better to have diffirent teout in different functions ?
I.e. receivehttpfile may have bigger timeout than httprequest
Since simple requests are usyally queries and small data
While files are bigger
For example an applications that send requests to receive files
(Http downloader) send a tiny request ,while it may receive huge file
In this case, 2 functions can be created, like CURL: Timeout for connection (curl --connect-timeout) and Timeout Max (curl --max-time)
See here: https://everything.curl.dev/usingcurl/timeouts
Re: PureBasic 6.00 Beta 9 released !
Or as Wayne-c suggested, you just call HttpTimeout() when you want to change it.
Would be no different than how you have to call DrawingMode() every time you want the graphics output changed.
Would be no different than how you have to call DrawingMode() every time you want the graphics output changed.



