Page 36 of 42

Re: PureBasic 6.00 Beta 9 released !

Posted: Sat Jun 04, 2022 9:04 am
by Rinzwind
Thanks for the http timeout option. Convenient.

Re: PureBasic 6.00 Beta 9 released !

Posted: Sat Jun 04, 2022 1:33 pm
by Marc56us
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.
Yes,
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 !

Posted: Sat Jun 04, 2022 4:16 pm
by RichAlgeni
Marc56us 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 ?)
+1

Re: PureBasic 6.00 Beta 9 released !

Posted: Sat Jun 04, 2022 7:36 pm
by Fred
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

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 12:51 am
by DeanH
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?

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 2:11 am
by BarryG
.

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 3:53 am
by Paul
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.
The same can be said for those who never have a need to change the timeout but always use the headers... like myself. ;)


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
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.

BarryG wrote:And a simple macro at the start of a source will reverse the order to not break any existing code.
Maybe you could demonstrate a macro that allows you to move the Header() part around?

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 5:24 am
by BarryG
Paul wrote: Sun Jun 05, 2022 3:53 amMaybe you could demonstrate a macro that allows you to move the Header() part around?
My bad; I didn't realise the parameters used a map. But macros support maps, so it should still be possible?

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 6:55 am
by Marc56us
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.

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"
EndIf
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.

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 3:19 pm
by Paul
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 ?
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)

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$())
And once again for consistency it would make more sense to use #PB_Ignore (maybe a feature request?)

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 4:12 pm
by wayne-c
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.

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 5:15 pm
by Marc56us
wayne-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.
+1
Very good solution!
:P

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 5:18 pm
by plouf
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

Re: PureBasic 6.00 Beta 9 released !

Posted: Sun Jun 05, 2022 5:36 pm
by Marc56us
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
Yes,
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 !

Posted: Sun Jun 05, 2022 5:43 pm
by Paul
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.