21 #ifndef G_HTTP_CLIENT_PARSER__H
22 #define G_HTTP_CLIENT_PARSER__H
33 class HttpClientParser ;
57 void apply(
const char * p ,
size_t n ) ;
83 std::vector<size_t>
headers(
const std::string & header_key )
const ;
86 std::string
header(
const std::string & header_key ,
const std::string & default_ = std::string() )
const ;
90 std::string
header(
size_t index ,
const std::string & default_ = std::string() )
const ;
93 int headerValue(
const std::string & header_key ,
int default_ = -1 )
const ;
96 int headerValue(
size_t header_index ,
int default_ = -1 )
const ;
99 std::string
headerWord(
const std::string & header_key ,
const std::string & default_ = std::string() )
const ;
102 std::string
headerWord(
size_t header_index ,
const std::string & default_ = std::string() )
const ;
105 std::string
headerAttribute(
const std::string & header_key ,
const std::string & attribute_key ,
106 const std::string & default_ = std::string() )
const ;
109 std::string
headerAttribute(
size_t header_index ,
const std::string & attribute_key ,
110 const std::string & default_ = std::string() )
const ;
126 std::string
body()
const ;
160 struct ResponseStatusInfo
162 ResponseStatusInfo() ;
173 std::string m_value ;
175 explicit HeaderInfo(
const std::string & line_ ) ;
176 bool match(
const std::string & key )
const ;
177 int value(
int default_ )
const ;
181 PartInfo() : start(0U) , headersize(0U) , bodysize(0U) {}
187 typedef std::vector<HeaderInfo> List ;
188 static List::const_iterator hfind(
const List & ,
const std::string & ) ;
189 static List::const_iterator hfind(
const List & ,
size_t ) ;
190 static List headerInfo(
const std::string & ) ;
191 static ResponseStatusInfo responseStatusInfo(
const std::string & ,
const std::string & ) ;
192 PartInfo partInfo()
const ;
193 std::string headerMultipartBoundary()
const ;
194 std::string
headerAttribute( List::const_iterator ,
const std::string & ,
const std::string & )
const ;
199 std::string::size_type m_sep ;
201 ResponseStatusInfo m_response_status ;
std::string header(const std::string &header_key, const std::string &default_=std::string()) const
Returns the value of the given header.
bool gotBody() const
Returns true if the body is complete.
std::vector< size_t > headers(const std::string &header_key) const
Returns the indexes for the headers with the given key.
int headerValue(const std::string &header_key, int default_=-1) const
Returns the integer value of a numeric header.
size_t headerCount() const
Returns the number of headers.
std::string headerContentType() const
Returns the value of the "Content-Type" header.
std::vector< std::string > StringArray
A std::vector of std::strings.
bool responseUnauthorised() const
Returns true for a "401 Unauthorized" response.
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.
bool gotPart() const
Returns true if a multipart part is complete.
bool responseOk() const
Returns true for a 2xx response.
A parser for HTTP responses received from a remote server.
std::string partType() const
Returns the content-type of the part.
bool gotHeaders() const
Returns true if headers are complete.
void clear()
Clears the contents, returning the object to a newly-constructed state.
bool headerMultipart() const
Returns true if the main body is of type "multipart".
bool responseRetry() const
Returns true for a 503 response.
void clearPart()
Clears the current multipart body part.
size_t headerContentLength() const
Returns the value of the "Content-Length" header.
int responseValue() const
Returns the response value (eg. 200), or minus one.
size_t partSize() const
Returns the part size.
HttpClientParser(const std::string &protocol=std::string())
Constructor. The protocol defaults to "HTTP".
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 responseSummary() const
Returns a summary of the response for debugging and error reporting.
const char * partData() const
Returns the part data.
std::string body() const
Returns the body data.
void apply(const char *p, size_t n)
Adds some data.
const char * bodyData() const
Returns the body data.
size_t bodySize() const
Returns the body size.