PureBasic 6.00 released !

Developed or developing a new product in PureBasic? Tell the world about it.
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: PureBasic 6.00 Beta 9 released !

Post by Rinzwind »

Thanks for the http timeout option. Convenient.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: PureBasic 6.00 Beta 9 released !

Post 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 ?)
User avatar
RichAlgeni
Addict
Addict
Posts: 914
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: PureBasic 6.00 Beta 9 released !

Post 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
Fred
Administrator
Administrator
Posts: 16664
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureBasic 6.00 Beta 9 released !

Post 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
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 224
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: PureBasic 6.00 Beta 9 released !

Post 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?
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

Re: PureBasic 6.00 Beta 9 released !

Post by BarryG »

.
Last edited by BarryG on Sun Jun 05, 2022 5:23 am, edited 1 time in total.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1251
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: PureBasic 6.00 Beta 9 released !

Post 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?
Image Image
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

Re: PureBasic 6.00 Beta 9 released !

Post 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?
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: PureBasic 6.00 Beta 9 released !

Post 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.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1251
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: PureBasic 6.00 Beta 9 released !

Post 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?)
Image Image
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Re: PureBasic 6.00 Beta 9 released !

Post 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.
As you walk on by, Will you call my name? Or will you walk away?
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: PureBasic 6.00 Beta 9 released !

Post 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
plouf
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Re: PureBasic 6.00 Beta 9 released !

Post 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
Christos
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: PureBasic 6.00 Beta 9 released !

Post 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
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1251
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: PureBasic 6.00 Beta 9 released !

Post 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.
Image Image
Post Reply