VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GNet::HttpClientParser Class Reference

A parser for HTTP responses received from a remote server. More...

#include <ghttpclientparser.h>

Public Member Functions

 HttpClientParser (const std::string &protocol=std::string())
 Constructor. The protocol defaults to "HTTP".
 
void apply (const char *p, size_t n)
 Adds some data.
 
void clear ()
 Clears the contents, returning the object to a newly-constructed state. More...
 
bool gotHeaders () const
 Returns true if headers are complete.
 
size_t headerCount () const
 Returns the number of headers.
 
bool responseOk () const
 Returns true for a 2xx response.
 
bool responseRetry () const
 Returns true for a 503 response.
 
bool responseUnauthorised () const
 Returns true for a "401 Unauthorized" response.
 
int responseValue () const
 Returns the response value (eg. 200), or minus one.
 
std::vector< size_t > headers (const std::string &header_key) const
 Returns the indexes for the headers with the given key.
 
std::string header (const std::string &header_key, const std::string &default_=std::string()) const
 Returns the value of the given header. More...
 
std::string header (size_t index, const std::string &default_=std::string()) const
 Overload using the header index.
 
int headerValue (const std::string &header_key, int default_=-1) const
 Returns the integer value of a numeric header.
 
int headerValue (size_t header_index, int default_=-1) const
 Overload using the header index.
 
std::string headerWord (const std::string &header_key, const std::string &default_=std::string()) const
 Returns the first part of the header with the given key.
 
std::string headerWord (size_t header_index, const std::string &default_=std::string()) const
 Overload using the header index.
 
std::string headerAttribute (const std::string &header_key, const std::string &attribute_key, const std::string &default_=std::string()) const
 Returns a named attribute of the specified header.
 
std::string headerAttribute (size_t header_index, const std::string &attribute_key, const std::string &default_=std::string()) const
 Overload using the header index.
 
std::string headerContentType () const
 Returns the value of the "Content-Type" header.
 
size_t headerContentLength () const
 Returns the value of the "Content-Length" header. More...
 
void clearPart ()
 Clears the current multipart body part.
 
bool gotBody () const
 Returns true if the body is complete.
 
std::string body () const
 Returns the body data. More...
 
const char * bodyData () const
 Returns the body data. More...
 
size_t bodySize () const
 Returns the body size. More...
 
bool headerMultipart () const
 Returns true if the main body is of type "multipart".
 
bool gotPart () const
 Returns true if a multipart part is complete.
 
std::string partType () const
 Returns the content-type of the part. More...
 
const char * partData () const
 Returns the part data. More...
 
size_t partSize () const
 Returns the part size. More...
 
std::string responseSummary () const
 Returns a summary of the response for debugging and error reporting.
 

Detailed Description

A parser for HTTP responses received from a remote server.

Also works for RTSP.

The response is structured as a status line, followed by an optional set of headers, then a blank line, and then the optional body.

Data is added incrementally with apply(), and gotHeaders() and gotBody() indicate how complete the response is.

The body can be multi-part, as indicated by headerMultipart(). Multi-part streams can be be unending, so individual parts should normally be cleared once they have been processed (see gotPart(), partData() and clearPart()).

Definition at line 51 of file ghttpclientparser.h.

Member Function Documentation

std::string GNet::HttpClientParser::body ( ) const

Returns the body data.

Precondition: gotBody()

Definition at line 298 of file ghttpclientparser.cpp.

const char * GNet::HttpClientParser::bodyData ( ) const

Returns the body data.

Precondition: gotBody()

Definition at line 303 of file ghttpclientparser.cpp.

size_t GNet::HttpClientParser::bodySize ( ) const

Returns the body size.

Precondition: gotBody()

Definition at line 308 of file ghttpclientparser.cpp.

void GNet::HttpClientParser::clear ( )

Clears the contents, returning the object to a newly-constructed state.

This is preferable to destruction and construction because the internal receive buffer can be large.

Definition at line 76 of file ghttpclientparser.cpp.

std::string GNet::HttpClientParser::header ( const std::string &  header_key,
const std::string &  default_ = std::string() 
) const

Returns the value of the given header.

If the header is repeated then only the first one is relevant.

Definition at line 198 of file ghttpclientparser.cpp.

size_t GNet::HttpClientParser::headerContentLength ( ) const

Returns the value of the "Content-Length" header.

Returns zero on error.

Definition at line 222 of file ghttpclientparser.cpp.

const char * GNet::HttpClientParser::partData ( ) const

Returns the part data.

Precondition: gotPart()

Definition at line 351 of file ghttpclientparser.cpp.

size_t GNet::HttpClientParser::partSize ( ) const

Returns the part size.

Precondition: gotPart()

Definition at line 357 of file ghttpclientparser.cpp.

std::string GNet::HttpClientParser::partType ( ) const

Returns the content-type of the part.

Precondition: gotPart()

Definition at line 363 of file ghttpclientparser.cpp.


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