[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Perform a "HEAD" operation



This seems to work. Added the code just before "receive the document from the server" in do_oper. I am not sure that is best place for it but it passed the simple tests I used.

--new--
C*********************************************************         
C* HEAD request is ended here - if response is 200 return 1 (good) 
C*********************************************************         
c                   if        peOper='HEAD'                        
                                                                   
c                   if        rc=200                               
c                   return    1                                    
c                   else                                           
c                   return    rc                                   
c                   endif                                          
                                                                   
c                   endif          
--end new--
C*********************************************************   
C* receive the document from the server                      
C*********************************************************   


I noticed OP program was looking for 0, but http_persist_req says it returns 1 if successful and do_oper sets the RC. According to my research, a HEAD will return a 200, so that is successful.

Anyone else confirm this works for a HEAD request and still works for other programs you have written?



-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Tuesday, July 01, 2014 5:07 PM
To: HTTPAPI and FTPAPI Projects
Subject: Re: Perform a "HEAD" operation

The trouble here is that HTTPAPI is seeing a content-length header of 
7058 characters.  As such, it's trying to receive that many characters 
in response -- which won't happen, here, because the HEAD method doesn't 
return ANY content, ever.

This is a bug in HTTPAPI.  I don't think anyone has ever tried using it 
with HEAD before -- it should ignore the content-length when HEAD is 
given, and assume the body of the document to always be 0 bytes long.


On 7/1/2014 11:29 AM, Mike Krebs wrote:
> I changed the program to point to a different resource and received a different and perhaps more telling error.
> --------debug.txt----------------
> HTTPAPI Ver 1.25beta2 released 2012-03-06
> OS/400 Ver V7R1M0
> ...
> Server: Microsoft-IIS/8.0
> Set-Cookie: ASPSESSIONIDQQDQTSTB=BBHBLEDBFOAJNDJMNGPBIJPJ; path=/
> X-Powered-By: ASP.NET
> Date: Tue, 01 Jul 2014 16:12:24 GMT
>                                                                                             
>                                                                                             
> 2014-07-01-11.12.28.337000 SetError() #13: HTTP/1.1 200 OK
> 2014-07-01-11.12.28.337000 recvresp(): end with 200
> 2014-07-01-11.12.28.337000 recvdoc parms: identity 7058
> 2014-07-01-11.12.28.338000 header_load_cookies() entered
> 2014-07-01-11.12.28.338000 cookie_parse() entered
> 2014-07-01-11.12.28.338000 cookie =  ASPSESSIONIDQQDQTSTB=BBHBLEDBFOAJNDJMNGPBIJPJ; path=/
> 2014-07-01-11.12.28.339000 cookie attr ASPSESSIONIDQQDQTSTB=BBHBLEDBFOAJNDJMNGPBIJPJ
> 2014-07-01-11.12.28.339000 cookie attr path=/
> 2014-07-01-11.12.28.339000 recvdoc(): entered
> 2014-07-01-11.12.28.339000 SetError() #0:
> 2014-07-01-11.13.28.369000 SetError() #43: CommTCP_read: time-out!
> 2014-07-01-11.13.30.499000 http_close(): entered
>
> It appears that HTTPAPI went back for more data for some reason as recvdoc was entered after parsing the header. I see that in Hannes's debug as well although his ended with a #0.
>   
>
> -----Original Message-----
> From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Hannes Rosner
> Sent: Tuesday, July 01, 2014 10:14 AM
> To: 'HTTPAPI and FTPAPI Projects'
> Subject: AW: Perform a "HEAD" operation
>
> I have made the suggested changes and added a "SaveProc" to the http_persist_call.
>
> But the result is the same, I will get a "rc= -1" from the
> http_persist_req() call and not the expected "200".
>
>   
>
> Hannes
>
>   
>
>   
>
> =============== Debug file ==================
>
> ***************Datenanfang*****************
>
> HTTPAPI Ver 1.24 released 2012-01-23
>
> OS/400 Ver V5R4M0
>
>   
>
> New iconv() objects set, PostRem=819. PostLoc=0. ProtRem=819. ProtLoc=0
>
> http_persist_open(): entered
>
> http_long_ParseURL(): entered
>
> DNS resolver retrans: 2
>
> DNS resolver retry  : 2
>
> DNS resolver options: x'00000136'
>
> DNS default domain: X****X.AT
>
> DNS server found: 10.1.2.11
>
> DNS server found: 10.1.2.196
>
> http_persist_req(HEAD) entered.
>
> http_long_ParseURL(): entered
>
> do_oper(HEAD): entered
>
> There are 0 cookies in the cache
>
> HEAD /img/logo.png HTTP/1.1
>
> Host: www.wikipedia.de
>
> Host: www.wikipedia.de
>
> User-Agent: http-api/1.24
>
>                                              
>
>                                              
>
> recvresp(): entered
>
> HTTP/1.1 200 OK
>
> Server: nginx/0.7.67
>
> Date: Tue, 01 Jul 2014 14:49:48 GMT
>
> Content-Type: image/png
>
> Content-Length: 11518
>
> Last-Modified: Fri, 27 Jul 2012 10:31:32 GMT
>
> Connection: keep-alive
>
> Accept-Ranges: bytes
>
>                                              
>
>                                              
>
> SetError() #13: HTTP/1.1 200 OK
>
> recvresp(): end with 200
>
> recvdoc parms: identity 11518
>
> header_load_cookies() entered
>
> header_load_cookies() entered
>
> recvdoc(): entered
>
> SetError() #0:
>
> http_close(): entered
>
>   ***************Datenende*******************
>
>   
>
>   
>
> ==================== Program =======================
>
> h DftActGrp( *NO ) ActGrp('TEST')
>
>
> h BndDir('LIBHTTP/HTTPAPI')
>
>
> h Option( *NoDebugIO           :*SrcStmt :*SecLvl )
>
>
>   
>
>
> d Main            pr                  ExtPgm('TEST17R')
>
>
>   
>
>
> d Main            pi
>
>
>   
>
>
>   /Copy LIBHTTP/QRPGLESRC,HttpApi_h          Routines for working with
> Headers & Cookies
>
>   /Copy LIBHTTP/QRPGLESRC,IFSio_h            Integrated File System API
> Header File
>
>   
>
>
> d RcvData         pr            10i 0
>
>
> d  peFD                         10i 0 Value
>
>
> d  peData                         *   Value
>
>
> d  peLength                     10i 0 Value
>
>
>   
>
>
> d PsDs           sds                  Qualified NoOpt
>
>
> d  ProcName         *PROC
>
>
>   
>
>
> d  msg            s             52a   Inz
>
> d  URL            s            300a   Inz Varying
>
> d  IFS            s            256a   Inz Varying
>
> d  wwComm         s               *
>
> d  fd             s             10i 0 Inz
>
> d  rc             s             10i 0 Inz
>
> d  ErrNo          s             10i 0 Inz
>
> d  header         s          32500a   Inz Varying
>
>                                                                              
>
>   /Free
>
>                                                                              
>
>       *INLR = *ON;
>
>       http_debug(*ON :'/tmp/httpapi_debug.' +%Trim(psds.ProcName) + '.txt');
>
>                                                                              
>
>    // IFS      = http_tempfile();
>
>    // fd  = open(IFS: O_WRONLY + O_TRUNC + O_CREAT + O_CCSID: 511:1208);
>
>       URL = 'http://www.wikipedia.de/img/logo.png';
>
>                                                                              
>
>       wwComm = http_persist_open( URL );
>
>                                                                              
>
>      If  ( wwComm = *NULL );
>
>          http_crash();
>
>      EndIF;
>
>                                                                              
>
>      rc = http_persist_req('HEAD'          // Method Type: 10a
>
>                           : wwComm         // HTTP Comm Session Type:*
>
>                           : URL            // URL    Type:  a
>
>                           : 0              // Upload fd    Type: 10i 0
>
>                           : *NULL          // Upload Proc  Type: *
>
>                           : *NULL          // Upload Data  Type: *
>
>                           : 0              // Upload Data length Type: 10i 0
>
>                           : 0              // Save fd          Type: 10i 0
>
>                           : %Paddr( RcvData ) // Save Proc Type: *
>
>                           );
>
>                                                                              
>
>      If  ( rc <> 0 );
>
>          Dsply ( 'rc= ' + %Char( rc ));
>
>          msg = http_error( ErrNo );
>
>          Dsply ( 'ErrNo= ' + %Char( ErrNo ));
>
>          Dsply ( msg );
>
>       EndIF;
>
>                                                                              
>
>       http_persist_close( wwComm );
>
>                                                                              
>
>       Return;
>
>                                                                              
>
>   /End-Free
>
>                                                                              
>
> p RcvData         b
>
> d RcvData         pi            10i 0
>
> d  peFD                         10i 0 Value
>
> d  peData                         *   Value
>
> d  peLength                     10i 0 Value
>
>   /Free
>
>                                                                              
>
>       Return peLength;
>
>                                                                              
>
> /End-Free
>
> p RcvData         e
>
> ******************Datenende ***********************************************
>
> ===========================================
>
>   
>
> -----------------------------------------------------------------------
> This is the FTPAPI mailing list.  To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------
>

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------