http_stmf and large files

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
Annemiek
Posts: 7
Joined: Tue Aug 29, 2023 9:52 am

http_stmf and large files

Post by Annemiek »

I'm using http_stmf to GET a large file and write it to the IFS. The thing is, sometimes this works fine and sometimes http_stmf runs into a timeout somewhere. I've tried multiple times with the same file.

Here's part of the log of a failed try:

Code: Select all

do_oper(GET): entered                                 
There are 1 cookies in the cache                      
GET /rest/api/v1/File/13/101014 HTTP/1.1              
Host: ???????????????????                           
User-Agent: http-api/1.38                             
Cookie: $Version=0; .X10Gateway.Session=????????????????????
Authorization:Bearer ?????????????????????????????????????
                                                                                                            
recvresp(): entered                                   
HTTP/1.1 200 OK                                       
Content-Length: 24455627                              
Content-Type: application/pdf                         
Content-Disposition: attachment; filename="page.pdf"  
api-supported-versions: 1.0                           
X-XSS-Protection: 1; mode=block                       
X-Content-Type-Options: nosniff                       
Date: Thu, 09 Nov 2023 13:57:50 GMT                   
SetError() #13: HTTP/1.1 200 OK         
recvresp(): end with 200                
recvdoc parms: identity 24455627        
header_load_cookies() entered           
recvdoc(): entered                      
SetError() #0:                 
recvdoc(): Receiving 24455627 bytes.    
And here's part of the log of a successful try:

Code: Select all

do_oper(GET): entered                        
There are 1 cookies in the cache             
GET /rest/api/v1/File/13/101014 HTTP/1.1     
Host: ????????????????????               
User-Agent: http-api/1.38                    
Cookie: $Version=0; .X10Gateway.Session=??????????????
Authorization:Bearer ??????????????????
                                                                                          
recvresp(): entered                          
HTTP/1.1 200 OK      
Content-Length: 24455627                              
Content-Type: application/pdf                         
Content-Disposition: attachment; filename="page.pdf"  
api-supported-versions: 1.0                           
X-XSS-Protection: 1; mode=block                       
X-Content-Type-Options: nosniff                       
Date: Thu, 09 Nov 2023 14:37:18 GMT                   
                                                      
                                                      
SetError() #13: HTTP/1.1 200 OK                       
recvresp(): end with 200                              
recvdoc parms: identity 24455627                      
header_load_cookies() entered                         
recvdoc(): entered                                    
SetError() #0:                                        
recvdoc(): Receiving 24455627 bytes.   


Frankly, I can't see any difference. Even in the successful try I can see the line SetError() #0: , but I still get a complete file. In the unsuccessful tries I get a partial file.

I have a few questions:
- Is this related to HTTPAPI or is this caused by the host?
- Is this a known issue that is solved in newer versions of HTTPAPI?
- Is there something I can do in my RPG-code?

I would really appreciate it if you can help!
Thanks,
Annemiek.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: http_stmf and large files

Post by Scott Klement »

Are you receiving a timeout error? Or, what error are you receiving from HTTPAPI?

There are changes, especially with SSL processing, in newer versions of HTTPAPI -- but it's hard to tell if that's teh problem you're running into.

Aside from that -- a timeout is normally caused by the network connection, or by the host computer, not by HTTPAPI.
Annemiek
Posts: 7
Joined: Tue Aug 29, 2023 9:52 am

Re: http_stmf and large files

Post by Annemiek »

Thanks for taking the time to look into my problem!

My code is pretty simple:

Code: Select all

         Monitor;
           http_stmf('GET': srvURL: IFSfile);
         On-error;
            http_error(*omit: respCode);
            // Checking respCode here
         EndMon;
On failed attempts the On-error branch is triggered and respCode is 0 (time-out).
On successful attempts, the program doesn't run into the On-error branch.
In both cases I'm trying to download the same file. On successful attempts, I'm getting the complete file and on failed tries I get a partial file.

Edit: I forgot to mention, that a successful attempt takes 10-15 seconds and a failed attempt anywhere between 2-15 seconds.

Thanks again,
Annemiek.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: http_stmf and large files

Post by Scott Klement »

In this example 'respCode' is the HTTP status code. 0 does not mean timeout, it means that you didn't get an HTTP status code.

What error is found in the job log?
Annemiek
Posts: 7
Joined: Tue Aug 29, 2023 9:52 am

Re: http_stmf and large files

Post by Annemiek »

All I can see in my joblog is CPF9897, no additional information.
I disabled the Monitor in my code to see if that would yield more information, but no.

Edit: I am debugging HHTPAPIR4. The statement that failed is "rc = http_req(Type: URL: RespStmf);". rc= -1 and the result of http_error() is blank. I"ll try to delve deeper.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: http_stmf and large files

Post by Scott Klement »

The CPF9897 should have text describing what the problem is. If it does not, that would clearly be a bug, and you should update to the current HTTPAPI (you are many releases behind) to ensure that the bug is fixed.

You could also add the following code to your program (before calling any other HTTP routines):

Code: Select all

http_debug(*on: '/tmp/debug_log.txt');
This will create a diagnostic log in the IFS (with the pathname provided) that gives details of what is happening under the covers.
Annemiek
Posts: 7
Joined: Tue Aug 29, 2023 9:52 am

Re: http_stmf and large files

Post by Annemiek »

Thanks so much, Scott, we are going to update HTTPAPI.
Post Reply