#include <HTTPParser.hpp>
Inherited by pion::net::HTTPReader.
Definition at line 31 of file HTTPParser.hpp.
Public Member Functions | |
HTTPParser (const bool is_request, std::size_t max_content_length=DEFAULT_CONTENT_MAX) | |
virtual | ~HTTPParser () |
default destructor | |
boost::tribool | parse (HTTPMessage &http_msg) |
boost::tribool | parseMissingData (HTTPMessage &http_msg, std::size_t len) |
void | finish (HTTPMessage &http_msg) const |
void | setReadBuffer (const char *ptr, size_t len) |
void | loadReadPosition (const char *&read_ptr, const char *&read_end_ptr) const |
bool | checkPrematureEOF (HTTPMessage &http_msg) |
void | reset (void) |
resets the parser to its initial state | |
bool | eof (void) const |
returns true if there are no more bytes available in the read buffer | |
std::size_t | bytes_available (void) const |
returns the number of bytes available in the read buffer | |
std::size_t | gcount (void) const |
returns the number of bytes read during the last parse operation | |
std::size_t | getTotalBytesRead (void) const |
returns the total number of bytes read while parsing the HTTP message | |
std::size_t | getContentBytesRead (void) const |
returns the total number of bytes read while parsing the payload content | |
std::size_t | getMaxContentLength (void) const |
returns the maximum length for HTTP payload content | |
const std::string & | getRawHeaders (void) const |
returns the raw HTTP headers saved by the parser | |
bool | getSaveRawHeaders (void) const |
returns true if the parser is saving raw HTTP header contents | |
bool | isParsingRequest (void) const |
returns true if the parser is being used to parse an HTTP request | |
bool | isParsingResponse (void) const |
returns true if the parser is being used to parse an HTTP response | |
void | setMaxContentLength (std::size_t n) |
sets the maximum length for HTTP payload content | |
void | resetMaxContentLength (void) |
resets the maximum length for HTTP payload content to the default value | |
void | setSaveRawHeaders (bool b) |
sets parameter for saving raw HTTP header content | |
void | setLogger (PionLogger log_ptr) |
sets the logger to be used | |
PionLogger | getLogger (void) |
returns the logger currently in use | |
Static Public Member Functions | |
static bool | contentTypeIsUrlEncoded (HTTPRequest &http_request) |
static bool | parseURLEncoded (HTTPTypes::QueryParams &dict, const char *ptr, const std::size_t len) |
static bool | parseCookieHeader (HTTPTypes::CookieParams &dict, const char *ptr, const std::size_t len, bool set_cookie_header) |
static bool | parseCookieHeader (HTTPTypes::CookieParams &dict, const std::string &cookie_header, bool set_cookie_header) |
static bool | parseURLEncoded (HTTPTypes::QueryParams &dict, const std::string &query) |
Static Public Attributes | |
static const std::size_t | DEFAULT_CONTENT_MAX = 1024 * 1024 |
maximum length for HTTP payload content | |
Protected Member Functions | |
boost::tribool | parseHeaders (HTTPMessage &http_msg) |
void | updateMessageWithHeaderData (HTTPMessage &http_msg) const |
boost::tribool | finishHeaderParsing (HTTPMessage &http_msg) |
boost::tribool | parseChunks (HTTPMessage::ChunkCache &chunk_buffers) |
boost::tribool | consumeContent (HTTPMessage &http_msg) |
std::size_t | consumeContentAsNextChunk (HTTPMessage::ChunkCache &chunk_buffers) |
Static Protected Member Functions | |
static void | computeMsgStatus (HTTPMessage &http_msg, bool msg_parsed_ok) |
static bool | isChar (int c) |
static bool | isControl (int c) |
static bool | isSpecial (int c) |
static bool | isDigit (int c) |
static bool | isHexDigit (int c) |
static bool | isCookieAttribute (const std::string &name, bool set_cookie_header) |
Protected Attributes | |
PionLogger | m_logger |
primary logging interface used by this class | |
const bool | m_is_request |
true if the message is an HTTP request; false if it is an HTTP response | |
const char * | m_read_ptr |
points to the next character to be consumed in the read_buffer | |
const char * | m_read_end_ptr |
points to the end of the read_buffer (last byte + 1) | |
Static Protected Attributes | |
static const boost::uint32_t | STATUS_MESSAGE_MAX = 1024 |
maximum length for response status message | |
static const boost::uint32_t | METHOD_MAX = 1024 |
maximum length for the request method | |
static const boost::uint32_t | RESOURCE_MAX = 256 * 1024 |
maximum length for the resource requested | |
static const boost::uint32_t | QUERY_STRING_MAX = 1024 * 1024 |
maximum length for the query string | |
static const boost::uint32_t | HEADER_NAME_MAX = 1024 |
maximum length for an HTTP header name | |
static const boost::uint32_t | HEADER_VALUE_MAX = 1024 * 1024 |
maximum length for an HTTP header value | |
static const boost::uint32_t | QUERY_NAME_MAX = 1024 |
maximum length for the name of a query string variable | |
static const boost::uint32_t | QUERY_VALUE_MAX = 1024 * 1024 |
maximum length for the value of a query string variable | |
static const boost::uint32_t | COOKIE_NAME_MAX = 1024 |
maximum length for the name of a cookie name | |
static const boost::uint32_t | COOKIE_VALUE_MAX = 1024 * 1024 |
maximum length for the value of a cookie; also used for path and domain |
pion::net::HTTPParser::HTTPParser | ( | const bool | is_request, | |
std::size_t | max_content_length = DEFAULT_CONTENT_MAX | |||
) | [inline] |
creates new HTTPParser objects
is_request | if true, the message is parsed as an HTTP request; if false, the message is parsed as an HTTP response | |
max_content_length | maximum length for HTTP payload content |
Definition at line 47 of file HTTPParser.hpp.
bool pion::net::HTTPParser::checkPrematureEOF | ( | HTTPMessage & | http_msg | ) | [inline] |
checks to see if a premature EOF was encountered while parsing. This should be called if there is no more data to parse, and if the last call to the parse() function returned boost::indeterminate
http_mhttp://start.fedoraproject.org/sg | the HTTP message object being parsed |
Definition at line 123 of file HTTPParser.hpp.
References pion::net::HTTPMessage::concatenateChunks().
Referenced by pion::net::HTTPMessage::receive().
void pion::net::HTTPParser::computeMsgStatus | ( | HTTPMessage & | http_msg, | |
bool | msg_parsed_ok | |||
) | [static, protected] |
compute and sets a HTTP Message data integrity status
http_msg | target HTTP message | |
msg_parsed_ok | message parsing result |
Definition at line 1097 of file HTTPParser.cpp.
References pion::net::HTTPMessage::hasDataAfterMissingPackets(), pion::net::HTTPMessage::hasMissingPackets(), and pion::net::HTTPMessage::setStatus().
Referenced by finish(), parse(), and parseMissingData().
boost::tribool pion::net::HTTPParser::consumeContent | ( | HTTPMessage & | http_msg | ) | [protected] |
consumes payload content in the parser's read buffer
http_msg | the HTTP message object to consume content for |
Definition at line 987 of file HTTPParser.cpp.
References bytes_available(), pion::net::HTTPMessage::getContent(), and m_read_ptr.
Referenced by parse().
std::size_t pion::net::HTTPParser::consumeContentAsNextChunk | ( | HTTPMessage::ChunkCache & | chunk_buffers | ) | [protected] |
consume the bytes available in the read buffer, converting them into the next chunk for the HTTP message
chunk_buffers | buffers to be populated from parsing chunked content |
Definition at line 1029 of file HTTPParser.cpp.
References bytes_available(), m_read_end_ptr, and m_read_ptr.
Referenced by parse().
static bool pion::net::HTTPParser::contentTypeIsUrlEncoded | ( | HTTPRequest & | http_request | ) | [static] |
Determine if the Content-Type header is valid and has type "application/x-www-form-urlencoded", and if a charset parameter is found, save the value.
http_request | request whose Content-Type header is being analyzed |
void pion::net::HTTPParser::finish | ( | HTTPMessage & | http_msg | ) | const |
finishes parsing an HTTP response message
http_msg | the HTTP message object to finish |
Definition at line 1046 of file HTTPParser.cpp.
References computeMsgStatus(), pion::net::HTTPMessage::concatenateChunks(), pion::net::HTTPTypes::CONTENT_TYPE_URLENCODED, pion::net::HTTPMessage::createContentBuffer(), pion::net::HTTPMessage::getContent(), getContentBytesRead(), pion::net::HTTPMessage::getContentLength(), pion::net::HTTPMessage::getHeader(), pion::net::HTTPRequest::getQueryParams(), pion::net::HTTPTypes::HEADER_CONTENT_TYPE, isParsingRequest(), pion::net::HTTPMessage::isValid(), m_logger, parseURLEncoded(), pion::net::HTTPMessage::setContentLength(), pion::net::HTTPMessage::setIsValid(), and updateMessageWithHeaderData().
Referenced by parse(), and parseMissingData().
boost::tribool pion::net::HTTPParser::finishHeaderParsing | ( | HTTPMessage & | http_msg | ) | [protected] |
should be called after parsing HTTP headers, to prepare for payload content parsing available in the read buffer
http_msg | the HTTP message object to populate from parsing |
Definition at line 600 of file HTTPParser.cpp.
References pion::net::HTTPMessage::createContentBuffer(), pion::net::HTTPMessage::getChunkCache(), pion::net::HTTPMessage::getContentLength(), pion::net::HTTPMessage::hasHeader(), pion::net::HTTPTypes::HEADER_CONTENT_LENGTH, pion::net::HTTPMessage::isChunked(), pion::net::HTTPMessage::isContentLengthImplied(), m_is_request, m_logger, pion::net::HTTPMessage::setContentLength(), pion::net::HTTPMessage::updateContentLengthUsingHeader(), updateMessageWithHeaderData(), and pion::net::HTTPMessage::updateTransferCodingUsingHeader().
Referenced by parse().
void pion::net::HTTPParser::loadReadPosition | ( | const char *& | read_ptr, | |
const char *& | read_end_ptr | |||
) | const [inline] |
loads a read position bookmark
read_ptr | points to the next character to be consumed in the read_buffer | |
read_end_ptr | points to the end of the read_buffer (last byte + 1) |
Definition at line 109 of file HTTPParser.hpp.
Referenced by pion::net::HTTPMessage::receive().
boost::tribool pion::net::HTTPParser::parse | ( | HTTPMessage & | http_msg | ) |
parses an HTTP message including all payload content it might contain
http_msg | the HTTP message object to populate from parsing |
Definition at line 39 of file HTTPParser.cpp.
References computeMsgStatus(), pion::net::HTTPMessage::concatenateChunks(), consumeContent(), consumeContentAsNextChunk(), eof(), finish(), finishHeaderParsing(), pion::net::HTTPMessage::getChunkCache(), pion::net::HTTPMessage::hasMissingPackets(), parseChunks(), parseHeaders(), and pion::net::HTTPMessage::setDataAfterMissingPacket().
Referenced by pion::net::HTTPReader::consumeBytes(), and pion::net::HTTPMessage::receive().
boost::tribool pion::net::HTTPParser::parseChunks | ( | HTTPMessage::ChunkCache & | chunk_buffers | ) | [protected] |
parses a chunked HTTP message-body using bytes available in the read buffer
chunk_buffers | buffers to be populated from parsing chunked content |
Definition at line 856 of file HTTPParser.cpp.
References isHexDigit(), m_logger, m_read_end_ptr, and m_read_ptr.
Referenced by parse().
static bool pion::net::HTTPParser::parseCookieHeader | ( | HTTPTypes::CookieParams & | dict, | |
const std::string & | cookie_header, | |||
bool | set_cookie_header | |||
) | [inline, static] |
parse key-value pairs out of a "Cookie" request header (i.e. this=that; a=value)
dict | dictionary for key-values pairs | |
cookie_header | header string to be parsed | |
set_cookie_header | set true if parsing Set-Cookie response header |
Definition at line 240 of file HTTPParser.hpp.
static bool pion::net::HTTPParser::parseCookieHeader | ( | HTTPTypes::CookieParams & | dict, | |
const char * | ptr, | |||
const std::size_t | len, | |||
bool | set_cookie_header | |||
) | [static] |
parse key-value pairs out of a "Cookie" request header (i.e. this=that; a=value)
dict | dictionary for key-values pairs | |
ptr | points to the start of the header string to be parsed | |
len | length of the encoded string, in bytes | |
set_cookie_header | set true if parsing Set-Cookie response header |
Referenced by updateMessageWithHeaderData().
boost::tribool pion::net::HTTPParser::parseHeaders | ( | HTTPMessage & | http_msg | ) | [protected] |
parses an HTTP message up to the end of the headers using bytes available in the read buffer
http_msg | the HTTP message object to populate from parsing |
Definition at line 207 of file HTTPParser.cpp.
References pion::net::HTTPMessage::addHeader(), pion::net::HTTPMessage::getVersionMajor(), pion::net::HTTPMessage::getVersionMinor(), HEADER_NAME_MAX, HEADER_VALUE_MAX, isChar(), isControl(), isDigit(), isSpecial(), m_is_request, m_read_end_ptr, m_read_ptr, METHOD_MAX, QUERY_STRING_MAX, RESOURCE_MAX, pion::net::HTTPMessage::setVersionMajor(), pion::net::HTTPMessage::setVersionMinor(), and STATUS_MESSAGE_MAX.
Referenced by parse().
boost::tribool pion::net::HTTPParser::parseMissingData | ( | HTTPMessage & | http_msg, | |
std::size_t | len | |||
) |
attempts to continue parsing despite having missed data (length is known but content is not)
http_msg | the HTTP message object to populate from parsing | |
len | the length in bytes of the missing data |
Definition at line 111 of file HTTPParser.cpp.
References computeMsgStatus(), finish(), pion::net::HTTPMessage::getChunkCache(), pion::net::HTTPMessage::getContent(), and pion::net::HTTPMessage::setMissingPackets().
static bool pion::net::HTTPParser::parseURLEncoded | ( | HTTPTypes::QueryParams & | dict, | |
const std::string & | query | |||
) | [inline, static] |
parse key-value pairs out of a url-encoded string (i.e. this=that&a=value)
dict | dictionary for key-values pairs | |
query | the encoded query string to be parsed |
Definition at line 255 of file HTTPParser.hpp.
static bool pion::net::HTTPParser::parseURLEncoded | ( | HTTPTypes::QueryParams & | dict, | |
const char * | ptr, | |||
const std::size_t | len | |||
) | [static] |
parse key-value pairs out of a url-encoded string (i.e. this=that&a=value)
dict | dictionary for key-values pairs | |
ptr | points to the start of the encoded string | |
len | length of the encoded string, in bytes |
Referenced by finish(), and updateMessageWithHeaderData().
void pion::net::HTTPParser::setReadBuffer | ( | const char * | ptr, | |
size_t | len | |||
) | [inline] |
resets the location and size of the read buffer
ptr | pointer to the first bytes available to be read | |
len | number of bytes available to be read |
Definition at line 98 of file HTTPParser.hpp.
Referenced by pion::net::HTTPReader::consumeBytes(), and pion::net::HTTPMessage::receive().
void pion::net::HTTPParser::updateMessageWithHeaderData | ( | HTTPMessage & | http_msg | ) | const [protected] |
updates an HTTPMessage object with data obtained from parsing headers
http_msg | the HTTP message object to populate from parsing |
Definition at line 545 of file HTTPParser.cpp.
References pion::net::HTTPMessage::getCookieParams(), pion::net::HTTPMessage::getHeaders(), pion::net::HTTPRequest::getQueryParams(), pion::net::HTTPTypes::HEADER_COOKIE, pion::net::HTTPTypes::HEADER_SET_COOKIE, isParsingRequest(), m_logger, parseCookieHeader(), parseURLEncoded(), pion::net::HTTPRequest::setMethod(), pion::net::HTTPRequest::setQueryString(), pion::net::HTTPRequest::setResource(), pion::net::HTTPResponse::setStatusCode(), and pion::net::HTTPResponse::setStatusMessage().
Referenced by finish(), and finishHeaderParsing().