Return TypeFunction nameArguments
hzEcodehzHttpClient::TestPage(hzChain&,const hzUrl&,)

Declared in file: hzHttpClient.h
Defined in file : hzHttpClient.cpp

Function Logic:

0:START 1:hzChain::Clear hzChain::Clear hzChain::Clear hzUrl::Domain 2:!url.Domain() 3:hzChain::Printf 4:Return E_ARGUMENT 5:hzChain::Clear hzUrl::Resource 6:url.Resource() 7:hzUrl::Resource 8:items 9:items 10:m_AuthBasic 11:items 12:items hzUrl::Domain 13:m_Referer 14:items 15:items hzUrl::Domain hzTcpClient::Send rc 16:rc!=E_OK 17:hzUrl::Domain Err2Txt hzChain::Printf 18:Return rc 19:nTry<4&&!m_Header.Size(); 20:hzTcpClient::Recv rc 21:rc!=E_OK 22:rc==E_NOSOCKET 23:hzChain::Printf 24:hzUrl::Resource Err2Txt hzChain::Printf 25:!nRecv 26:hzChain::Printf sleep 27:hzChain::Append 28:rc!=E_OK 29:Err2Txt hzChain::Printf 30:Return rc 31:m_Referer 32:Return rc

Function body:

hzEcode hzHttpClient::TestPage (hzChain& Z, const hzUrl& url)
{
   _hzfunc("hzHttpClient::Testpage") ;
   chIter      zi ;
   chIter      hi ;
   chIter      ti ;
   hzChain     X ;
   hzCookie    cookie ;
   hzString    S ;
   hzString    param ;
   hzString    value ;
   hzString    encoding ;
   uint32_t    nRecv ;
   uint32_t    nTry ;
   hzEcode     rc = E_OK ;
   Z.Clear() ;
   m_Header.Clear() ;
   m_Content.Clear() ;
   if (!url.Domain())
       { m_Error.Printf("TestPage: No host to locate\n") ; return E_ARGUMENT ; }
   /*
   **  ** Formulate HTTP request
   **      */
   m_Request.Clear() ;
   if (url.Resource())
       m_Request << "GET " <<  url.Resource() << " HTTP/1.1\r\n" ;
   else
       m_Request << "GET / HTTP/1.1\r\n" ;
   m_Request <<
   "Accept: */*\r\nAccept-Language: en-gb\r\n"
                                ;
   if (m_AuthBasic)
       m_Request << "Authorization: Basic " << m_AuthBasic << "\r\n" ;
   m_Request << "User-Agent: HadronZoo/0.8 Linux 2.6.18\r\n" ;
   m_Request << "Host: " << url.Domain() << "\r\n" ;
   if (m_Referer)
       m_Request << "Referer: " << m_Referer << "\r\n" ;
   m_Request << "Connection: Keep-Alive\r\n\r\n" ;
   /*
   **  ** Send request
   **      */
   m_Error << " Sending [" << m_Request << "] to domain " << url.Domain() << "\n" ;
   rc = m_Webhost.Send(m_Request) ;
   if (rc != E_OK)
   {
       m_Error.Printf("Could not send request to domain [%s] (error=%s)\n", *url.Domain(), Err2Txt(rc)) ;
       return rc ;
   }
   for (nTry = 0; nTry < 4&& !m_Header.Size() ; nTry++)
   {
       rc = m_Webhost.Recv(m_buf, nRecv, HZ_MAXPACKET) ;
       if (rc != E_OK)
       {
           if (rc == E_NOSOCKET)
               m_Error.Printf("Connection closed by server\n") ;
           else
               m_Error.Printf("Could not recv bytes (nbytes=%d) from page %s (error=%s)\n", nRecv, *url.Resource(), Err2Txt(rc)) ;
           break ;
       }
       if (!nRecv)
       {
           m_Error.Printf("Got no response, retrying ...\n") ;
           sleep(1);
           continue ;
       }
       Z.Append(m_buf, nRecv) ;
   }
   if (rc != E_OK)
   {
       m_Error.Printf("Could not process response from [%s] (error=%s)\n", *url, Err2Txt(rc)) ;
       return rc ;
   }
   m_Referer = url ;
   return rc ;
}