![]() |
Gray C++ Libraries
0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
|
#include <cHttpClient.h>
Public Member Functions | |
cHttpClient (cStream *pStream=nullptr, const char *pszServerURL=nullptr, const char *pszAgentName=GRAY_NAMES) | |
virtual | ~cHttpClient () |
void | AttachStream (cStream *pStream) |
cStream * | get_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) | |
![]() | |
virtual | ~ IFileCopier () |
virtual HRESULT | SendAttr (const FILECHAR_t *pszDestName, cTimeFile timeChanged) |
![]() | |
UNITTEST_FRIEND (cHttpCommon) | |
Static Public Member Functions | |
static StrLen_t GRAYCALL | Encode_POST (char *pszArgs, StrLen_t nLenMax, const cIniSectionData &args) |
![]() | |
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 | |
cStream * | m_pStream |
the data stream to/from the HTTP server. may be cNetSocket -> cNetStream (or SSL or other) More... | |
Additional Inherited Members | |
![]() | |
static const size_t | k_CR_SIZE = 2 |
sizeof HTTP_CR "\r\n" More... | |
static const char * | k_Space = " " |
" " More... | |
static const char *const | k_szVerbs [HTTPVERB_QTY+1] |
static const cPairT< HTTPRET_TYPE, HRESULT > | k_HttpReturnErrors [] |
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.
GrayLib::cHttpClient::cHttpClient | ( | cStream * | pStream = nullptr , |
const char * | pszServerURL = nullptr , |
||
const char * | pszAgentName = GRAY_NAMES |
||
) |
URL can be filled in now or later.
|
virtual |
|
inline |
|
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.
|
static |
Prepare a post for sending back to a server.
|
overridevirtual |
get a debug name for the connection.
Implements Gray::IFileCopier.
|
inline |
HRESULT GrayLib::cHttpClient::ReadBodyChunk | ( | cHttpClientBody & | body | ) |
Read and process a chunk of data returned for the body of a request response.
|
overridevirtual |
Send a HTTPVERB_GET request to the HTTP server for the file. Wait for response. Blocking call.
Reimplemented from Gray::IFileCopier.
HRESULT GrayLib::cHttpClient::Send_GET | ( | HTTPVERB_TYPE | eVerb, |
cStringA | sObject | ||
) |
compose and send a Request HTTPVERB_GET for a page/file. Non blocking.
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.
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"
HRESULT GrayLib::cHttpClient::Send_POST | ( | const char * | pszReferer, |
const cIniSectionData & | args | ||
) |
opposite of cVarMap::AddHtmlArgsLen
|
overridevirtual |
Send a file from the client to the server. HTTPVERB_PUT verb or HTTPVERB_POST ? Wait for response. Blocking call.
Reimplemented from Gray::IFileCopier.
GrayLib::cHttpClient::UNITTEST_FRIEND | ( | cHttpClient | ) |
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 ?
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.
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.
//! 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> //!
//!
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> //!
|
protected |
the data stream to/from the HTTP server. may be cNetSocket -> cNetStream (or SSL or other)
const char* const GrayLib::cHttpClient::m_pszAgentName |
Who are we. Who is asking? e.g. I am a browser.
cNetURL GrayLib::cHttpClient::m_url |
The name of the host we are talking to. cNetAddrName -> cNetAddress.