Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cHttpClient Class Reference

#include <cHttpClient.h>

Inheritance diagram for GrayLib::cHttpClient:
Gray::IFileCopier GrayLib::cHttpCommon GrayLib::cHttpCopier GrayLib::cWebAPIClient

Public Member Functions

 cHttpClient (cStream *pStream=nullptr, const char *pszServerURL=nullptr, const char *pszAgentName=GRAY_NAMES)
 
virtual ~cHttpClient ()
 
void AttachStream (cStream *pStream)
 
cStreamget_Stream () const
 
HRESULT Send_GET (HTTPVERB_TYPE eVerb, cStringA sObject)
 
HRESULT Send_POST (const char *pszReferer, const char *pszArgs, StrLen_t nLenArgs)
 
HRESULT Send_POST (const char *pszReferer, const cIniSectionData &args)
 
HRESULT Send_POST (cHttpPart **ppParts, int iParts, IStreamProgressCallback *pProgress=nullptr)
 
virtual cStringA get_ConnectName () const override
 get a debug name for the connection. More...
 
virtual HRESULT Connect (const FILECHAR_t *pszServerURL) override
 
virtual HRESULT RequestFile (const FILECHAR_t *pszSrcName, const FILECHAR_t *pszDestPath, IStreamProgressCallback *pProgress, FILE_SIZE_t nOffsetStart, FILE_SIZE_t *pnRequestSizeEst) override
 
virtual HRESULT SendFile (const FILECHAR_t *pszSrcPath, const FILECHAR_t *pszDestName, IStreamProgressCallback *pProgress, FILE_SIZE_t nOffsetStart, FILE_SIZE_t nSize) override
 
HRESULT WaitForHeader (OUT cHttpHeaderServer &Head, IStreamProgressCallback *pProgress, TIMESYSD_t timeout=cTimeSys::k_DMAX)
 
HRESULT ReadBodyChunk (cHttpClientBody &body)
 
HRESULT WaitForBody (const cHttpHeader &Head, cStreamOutput *psBody, IStreamProgressCallback *pProgress, OUT FILE_SIZE_t *pnRequestSizeEst)
 
HRESULT WaitForResponse (OUT cHttpHeaderServer &Head, cStreamOutput *psBody, IStreamProgressCallback *pProgress, FILE_SIZE_t *pnRequestSizeEst)
 
 UNITTEST_FRIEND (cHttpClient)
 
- Public Member Functions inherited from Gray::IFileCopier
virtual ~ IFileCopier ()
 
virtual HRESULT SendAttr (const FILECHAR_t *pszDestName, cTimeFile timeChanged)
 
- Public Member Functions inherited from GrayLib::cHttpCommon
 UNITTEST_FRIEND (cHttpCommon)
 

Static Public Member Functions

static StrLen_t GRAYCALL Encode_POST (char *pszArgs, StrLen_t nLenMax, const cIniSectionData &args)
 
- Static Public Member Functions inherited from GrayLib::cHttpCommon
static HTTPVERB_TYPE GRAYCALL FindVerb (const char *pszVerb)
 
static HTTPRET_TYPE GRAYCALL GetErrorHttpRet (HRESULT hRes)
 
static HRESULT GRAYCALL GetErrorHResult (HTTPRET_TYPE eRetCode)
 
static cStringA GRAYCALL GetErrorText (HTTPRET_TYPE eRetCode)
 

Public Attributes

const char *const m_pszAgentName
 Who are we. Who is asking? e.g. I am a browser. More...
 
cNetURL m_url
 The name of the host we are talking to. cNetAddrName -> cNetAddress. More...
 

Protected Attributes

cStreamm_pStream
 the data stream to/from the HTTP server. may be cNetSocket -> cNetStream (or SSL or other) More...
 

Additional Inherited Members

- Static Public Attributes inherited from GrayLib::cHttpCommon
static const size_t k_CR_SIZE = 2
 sizeof HTTP_CR "\r\n" More...
 
static const char * k_Space = "&nbsp;"
 "&nbsp;" More...
 
static const char *const k_szVerbs [HTTPVERB_QTY+1]
 
static const cPairT< HTTPRET_TYPE, HRESULTk_HttpReturnErrors []
 

Detailed Description

I am the HTTP client. talk to some remote HTTP server. NOT Server side version of client connection (that is cHttpProtocolStream). Move pages/files to/from a HTTP connection. Does not do HTTPS. TODO Allow up to 10 levels of redirection? NO MORE.

Constructor & Destructor Documentation

◆ cHttpClient()

GrayLib::cHttpClient::cHttpClient ( cStream pStream = nullptr,
const char *  pszServerURL = nullptr,
const char *  pszAgentName = GRAY_NAMES 
)

URL can be filled in now or later.

◆ ~cHttpClient()

GrayLib::cHttpClient::~cHttpClient ( )
virtual

Member Function Documentation

◆ AttachStream()

void GrayLib::cHttpClient::AttachStream ( cStream pStream)
inline

◆ Connect()

HRESULT GrayLib::cHttpClient::Connect ( const FILECHAR_t pszServerURL)
overridevirtual

IFileCopier connect to the device by its name. to transfer files to/from. like cFileCopier::Connect() pszServerURL == nullptr = re-connect to the previous address.

Reimplemented from Gray::IFileCopier.

Reimplemented in GrayLib::cHttpCopier.

◆ Encode_POST()

StrLen_t GRAYCALL GrayLib::cHttpClient::Encode_POST ( char *  pszArgs,
StrLen_t  nLenMax,
const cIniSectionData args 
)
static

Prepare a post for sending back to a server.

◆ get_ConnectName()

cStringA GrayLib::cHttpClient::get_ConnectName ( ) const
overridevirtual

get a debug name for the connection.

Implements Gray::IFileCopier.

◆ get_Stream()

cStream* GrayLib::cHttpClient::get_Stream ( ) const
inline

◆ ReadBodyChunk()

HRESULT GrayLib::cHttpClient::ReadBodyChunk ( cHttpClientBody body)

Read and process a chunk of data returned for the body of a request response.

Returns
HRESULT_WIN32_C(ERROR_IO_INCOMPLETE) = roll back all data.
# of bytes i wish to consume. roll back anything else.

◆ RequestFile()

HRESULT GrayLib::cHttpClient::RequestFile ( const FILECHAR_t pszSrcName,
const FILECHAR_t pszDestPath,
IStreamProgressCallback pProgress,
FILE_SIZE_t  nOffsetStart,
FILE_SIZE_t pnRequestSizeEst 
)
overridevirtual

Send a HTTPVERB_GET request to the HTTP server for the file. Wait for response. Blocking call.

  • pszSrcName = server side name. NOT yet URLEnCode pszDestPath = local path, nullptr = just request stats for the file. nullptr = just asking the size. pnRequestSizeEst = assume the response will be this big. -1 = just ask how big.
    Returns
    S_OK = done. HRESULT_WIN32_C(RPC_X_PIPE_EMPTY), HRESULT_WIN32_C(ERROR_IO_INCOMPLETE) when we have no more data to process now. come back later.

Reimplemented from Gray::IFileCopier.

◆ Send_GET()

HRESULT GrayLib::cHttpClient::Send_GET ( HTTPVERB_TYPE  eVerb,
cStringA  sObject 
)

compose and send a Request HTTPVERB_GET for a page/file. Non blocking.

  • eVerb = HTTPVERB_GET, HTTPVERB_HEAD TODO send cookies as well ?

◆ Send_POST() [1/3]

HRESULT GrayLib::cHttpClient::Send_POST ( cHttpPart **  ppParts,
int  iParts,
IStreamProgressCallback pProgress = nullptr 
)

A big post. Send a HTTPVERB_POST args in "multipart/form-data" format.

◆ Send_POST() [2/3]

HRESULT GrayLib::cHttpClient::Send_POST ( const char *  pszReferer,
const char *  pszArgs,
StrLen_t  nLenArgs 
)

HTTPVERB_POST args in "application/x-www-form-urlencoded" format. e.g. separated by &. "T1=stuff1&B1=Submit&T2=stuff2"

◆ Send_POST() [3/3]

HRESULT GrayLib::cHttpClient::Send_POST ( const char *  pszReferer,
const cIniSectionData args 
)

◆ SendFile()

HRESULT GrayLib::cHttpClient::SendFile ( const FILECHAR_t pszSrcPath,
const FILECHAR_t pszDestName,
IStreamProgressCallback pProgress,
FILE_SIZE_t  nOffsetStart,
FILE_SIZE_t  nSize 
)
overridevirtual

Send a file from the client to the server. HTTPVERB_PUT verb or HTTPVERB_POST ? Wait for response. Blocking call.

  • pszSrcName = local side name.
  • pszDestPath = Far side name. (Not yet HTTP encoded)

Reimplemented from Gray::IFileCopier.

◆ UNITTEST_FRIEND()

GrayLib::cHttpClient::UNITTEST_FRIEND ( cHttpClient  )

◆ WaitForBody()

HRESULT GrayLib::cHttpClient::WaitForBody ( const cHttpHeader Head,
cStreamOutput psBody,
IStreamProgressCallback pProgress,
OUT FILE_SIZE_t pnRequestSizeEst 
)

Wait for the full response from the server. blocking call. OR Server wait for the body of a POST ?

◆ WaitForHeader()

HRESULT GrayLib::cHttpClient::WaitForHeader ( OUT cHttpHeaderServer Head,
IStreamProgressCallback pProgress,
TIMESYSD_t  timeout = cTimeSys::k_DMAX 
)

Wait for the header response from the server. blocking call.

◆ WaitForResponse()

HRESULT GrayLib::cHttpClient::WaitForResponse ( OUT cHttpHeaderServer Head,
cStreamOutput psBody,
IStreamProgressCallback pProgress,
FILE_SIZE_t pnRequestSizeEst 
)

Wait for a full response from a client command to the server. Blocking call.

  • psBody = put the body of data response here. if HTTPRET_OK_DATA
    Note
    in a chunked Encoded response the ContentLength tag is not supplied, so try to use pnRequestSizeEst
    Parse out the response like this:
    //! HTTP/1.1 200 OK\r\n
    //! Server: Microsoft-IIS/4.0\r\n
    //! Date: Tue, 03 Oct 2000 19:44:56 GMT\r\n
    //! Content-Type: text/html\r\n
    //! Accept-Ranges: bytes\r\n
    //! Last-Modified: Fri, 17 Dec 1999 14:59:20 GMT\r\n
    //! ETag: "094e54b9f48bf1:1f83"\r\n
    //! Content-Length: 1923\r\n
    //! \r\n
    //! stuff
    //!     
    or in the case of error:
    @verbatim
    
    //! HTTP/1.1 404 Object Not Found //! Server: Microsoft-IIS/4.0 //! Date: Wed, 18 Oct 2000 17:15:46 GMT //! Connection: close //! Content-Length: 461 //! Content-Type: text/html //! //! <html><head><title>Error 404</title> //! <meta name="robots" content="noindex"> //! <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"></head> //! <body> //!

    HTTP Error 404

//!

404 Not Found

//!

The Web server cannot find the file or script you asked for. Please check the URL to ensure that the path is correct

//!

Please contact the server's administrator if this problem persists.

//! </body></html> //!

Member Data Documentation

◆ m_pStream

cStream* GrayLib::cHttpClient::m_pStream
protected

the data stream to/from the HTTP server. may be cNetSocket -> cNetStream (or SSL or other)

◆ m_pszAgentName

const char* const GrayLib::cHttpClient::m_pszAgentName

Who are we. Who is asking? e.g. I am a browser.

◆ m_url

cNetURL GrayLib::cHttpClient::m_url

The name of the host we are talking to. cNetAddrName -> cNetAddress.


The documentation for this class was generated from the following files: