HTTPAPI Timeout question

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
assignment400
Posts: 12
Joined: Mon Aug 29, 2022 10:39 pm

HTTPAPI Timeout question

Post by assignment400 »

What happens in a HTTPAPI call when the target system is unavailable?

How long is the timeout wait?

Can the timeout period be reduced?

I am using HTTPAPI in an interactive situation. If there is a remote failure, we cannot have the system locking the system until the timeout expires. I would like to see if there is a way to identify the failure.

Thanks, Darryl Freinkel.
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: HTTPAPI Timeout question

Post by jonboy49 »

Most of the APIs in HTTPAPI offer an optional timeout parameter Darryl which allow you to specify the timeout delay in seconds. For example:

Code: Select all

     D http_get        PR            10I 0 extproc('HTTP_URL_GET')
     D  peURL                     32767A   varying const options(*varsize)
     D  peFilename                32767A   varying const options(*varsize)
     D  peTimeout                    10I 0 value options(*nopass)
     D  peUserAgent               16384A   varying const  options(*nopass:*omit)
     D  ...
The return code allow you to differentiate between success, failure, and timeout.

Just search the header file for the word "timeout" there's over 60 references.
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: HTTPAPI Timeout question

Post by Scott Klement »

I would prefer that people not use the old APIs like the one Jon posted for new applications.

Instead, use http_req, http_stmf or http_string.

Code: Select all

http_setOption('timeout': '30'); // time out after 30 seconds

rc = http_req(...parameters...);
You mention the other system is "unavailable". The timeout only applies to lack of data being received -- i.e. you try to connect and get no response, or you are expecting to be able to send or receive data and get no response for the given number of seconds.

Frequently when a system is unavailable, it's because the HTTP server isn't running on that system. In that case, you wouldn't get a timeout, you'd get an error connecting (typically "Connection Refused" but sometimes "Host not available") That is because the TCP/IP stack on the remote computer's operating system is still running, even if the program is not. And so it will send back an error code immediately.
assignment400
Posts: 12
Joined: Mon Aug 29, 2022 10:39 pm

Re: HTTPAPI Timeout question

Post by assignment400 »

Thank you.
I'll add your recommendation in the program.
Darryl.
Post Reply