![]() |
staticlib_pion
2.0.2
|
Parses HTTP messages. More...
#include <staticlib/pion/http_parser.hpp>
Classes | |
| class | error_category_t |
| Class-specific error category. More... | |
Public Types | |
| enum | error_value_t { ERROR_METHOD_CHAR = 1, ERROR_METHOD_SIZE, ERROR_URI_CHAR, ERROR_URI_SIZE, ERROR_QUERY_CHAR, ERROR_QUERY_SIZE, ERROR_VERSION_EMPTY, ERROR_VERSION_CHAR, ERROR_STATUS_EMPTY, ERROR_STATUS_CHAR, ERROR_HEADER_CHAR, ERROR_HEADER_NAME_SIZE, ERROR_HEADER_VALUE_SIZE, ERROR_INVALID_CONTENT_LENGTH, ERROR_CHUNK_CHAR, ERROR_MISSING_CHUNK_DATA, ERROR_MISSING_HEADER_DATA, ERROR_MISSING_TOO_MUCH_CONTENT } |
| Class-specific error code values. More... | |
Public Member Functions | |
| http_parser (size_t max_content_length=DEFAULT_CONTENT_MAX) | |
| Creates new parser objects. | |
| http_parser (const http_parser &) | |
| Deleted copy constructor. | |
| http_parser & | operator= (const http_parser &) |
| Deleted copy assignment operator. | |
| virtual | ~http_parser () STATICLIB_NOEXCEPT |
| Default destructor. | |
| sl::support::tribool | parse (http_message &http_msg, std::error_code &ec) |
| Parses an HTTP message including all payload content it might contain. | |
| void | finish (http_message &http_msg) const |
| Finishes parsing an HTTP response message. | |
| void | set_read_buffer (const char *ptr, size_t len) |
| Resets the location and size of the read buffer. | |
| void | load_read_pos (const char *&read_ptr, const char *&read_end_ptr) const |
| Loads a read position bookmark. | |
| bool | check_premature_eof (http_message &http_msg) |
| Checks to see if a premature EOF was encountered while parsing. | |
| void | parse_headers_only (bool b=true) |
| Controls headers-only parsing (default is disabled; content parsed also) | |
| void | skip_header_parsing (http_message &http_msg) |
| Skip parsing all headers and parse payload content only. | |
| void | reset () |
| Resets the parser to its initial state. | |
| bool | eof () const |
| Returns true if there are no more bytes available in the read buffer. | |
| size_t | bytes_available () const |
| Returns the number of bytes available in the read buffer. | |
| size_t | gcount () const |
| Returns the number of bytes read during the last parse operation. | |
| size_t | get_total_bytes_read () const |
| Returns the total number of bytes read while parsing the HTTP message. | |
| size_t | get_content_bytes_read () const |
| Returns the total number of bytes read while parsing the payload content. | |
| size_t | get_max_content_length () const |
| Returns the maximum length for HTTP payload content. | |
| const std::string & | get_raw_headers () const |
| Returns the raw HTTP headers saved by the parser. | |
| bool | get_save_raw_headers () const |
| Returns true if the parser is saving raw HTTP header contents. | |
| bool | get_parse_headers_only () |
| Returns true if parsing headers only. | |
| bool | is_parsing_request () const |
| Returns true if the parser is being used to parse an HTTP request. | |
| bool | is_parsing_response () const |
| Returns true if the parser is being used to parse an HTTP response. | |
| void | set_payload_handler (payload_handler_type &h) |
| Defines a callback function to be used for consuming payload content. | |
| void | set_max_content_length (size_t n) |
| Sets the maximum length for HTTP payload content. | |
| void | reset_max_content_length () |
| Resets the maximum length for HTTP payload content to the default value. | |
| void | set_save_raw_headers (bool b) |
| Sets parameter for saving raw HTTP header content. | |
| sl::support::tribool | finish_header_parsing (http_message &http_msg, std::error_code &ec) |
| Should be called after parsing HTTP headers, to prepare for payload content parsing available in the read buffer. | |
Static Public Member Functions | |
| static bool | parse_uri (const std::string &uri, std::string &proto, std::string &host, uint16_t &port, std::string &path, std::string &query) |
| Parses a URI string. | |
| static bool | parse_url_encoded (std::unordered_multimap< std::string, std::string, algorithm::ihash, algorithm::iequal_to > &dict, const char *ptr, const size_t len) |
| Parse key-value pairs out of a url-encoded string (i.e. | |
| static bool | parse_multipart_form_data (std::unordered_multimap< std::string, std::string, algorithm::ihash, algorithm::iequal_to > &dict, const std::string &content_type, const char *ptr, const size_t len) |
| Parse key-value pairs out of a multipart/form-data payload content (http://www.ietf.org/rfc/rfc2388.txt) | |
| static bool | parse_cookie_header (std::unordered_multimap< std::string, std::string, algorithm::ihash, algorithm::iequal_to > &dict, const char *ptr, const size_t len, bool set_cookie_header) |
| Parse key-value pairs out of a "Cookie" request header (i.e. | |
| static bool | parse_cookie_header (std::unordered_multimap< std::string, std::string, algorithm::ihash, algorithm::iequal_to > &dict, const std::string &cookie_header, bool set_cookie_header) |
| Parse key-value pairs out of a "Cookie" request header (i.e. | |
| static bool | parse_url_encoded (std::unordered_multimap< std::string, std::string, algorithm::ihash, algorithm::iequal_to > &dict, const std::string &query) |
| Parse key-value pairs out of a url-encoded string (i.e. | |
| static bool | parse_multipart_form_data (std::unordered_multimap< std::string, std::string, algorithm::ihash, algorithm::iequal_to > &dict, const std::string &content_type, const std::string &form_data) |
| Parse key-value pairs out of a multipart/form-data payload content (http://www.ietf.org/rfc/rfc2388.txt) | |
| static error_category_t & | get_error_category () |
| Returns an instance of parser::error_category_t. | |
Static Public Attributes | |
| static const size_t | DEFAULT_CONTENT_MAX |
| Maximum length for HTTP payload content (for non-streaming server) | |
Protected Member Functions | |
| virtual void | finished_parsing_headers (const std::error_code &, sl::support::tribool &) |
| Called after we have finished parsing the HTTP message headers. | |
| sl::support::tribool | parse_headers (http_message &http_msg, std::error_code &ec) |
| Parses an HTTP message up to the end of the headers using bytes available in the read buffer. | |
| void | update_message_with_header_data (http_message &http_msg) const |
| Updates an http::message object with data obtained from parsing headers. | |
| sl::support::tribool | parse_chunks (std::vector< char > &chunk_buffers, std::error_code &ec) |
| Parses a chunked HTTP message-body using bytes available in the read buffer. | |
| sl::support::tribool | consume_content (http_message &http_msg, std::error_code &ec) |
| Consumes payload content in the parser's read buffer. | |
| size_t | consume_content_as_next_chunk (std::vector< char > &chunk_buffers) |
| Consume the bytes available in the read buffer, converting them into the next chunk for the HTTP message. | |
Static Protected Member Functions | |
| static void | compute_msg_status (http_message &http_msg, bool msg_parsed_ok) |
| Compute and sets a HTTP Message data integrity status. | |
| static void | set_error (std::error_code &ec, error_value_t ev) |
| Sets an error code. | |
| static void | create_error_category () |
| Creates the unique parser error_category_t. | |
| static bool | is_digit (int c) |
| static bool | is_hex_digit (int c) |
| static bool | is_cookie_attribute (const std::string &name, bool set_cookie_header) |
Protected Attributes | |
| 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 uint32_t | STATUS_MESSAGE_MAX |
| Maximum length for response status message. | |
| static const uint32_t | METHOD_MAX |
| Maximum length for the request method. | |
| static const uint32_t | RESOURCE_MAX |
| Maximum length for the resource requested. | |
| static const uint32_t | QUERY_STRING_MAX |
| Maximum length for the query string. | |
| static const uint32_t | HEADER_NAME_MAX |
| Maximum length for an HTTP header name. | |
| static const uint32_t | HEADER_VALUE_MAX |
| Maximum length for an HTTP header value. | |
| static const uint32_t | QUERY_NAME_MAX |
| Maximum length for the name of a query string variable. | |
| static const uint32_t | QUERY_VALUE_MAX |
| Maximum length for the value of a query string variable. | |
| static const uint32_t | COOKIE_NAME_MAX |
| Maximum length for the name of a cookie name. | |
| static const uint32_t | COOKIE_VALUE_MAX |
| Maximum length for the value of a cookie; also used for path and domain. | |
Parses HTTP messages.
Class-specific error code values.
|
inline |
Creates new parser objects.
| max_content_length | maximum length for HTTP payload content |
| staticlib::pion::http_parser::http_parser | ( | const http_parser & | ) |
Deleted copy constructor.
|
inlinevirtual |
Default destructor.
|
inline |
Returns the number of bytes available in the read buffer.
|
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 indeterminate
| http_msg | the HTTP message object being parsed |
|
staticprotected |
Compute and sets a HTTP Message data integrity status.
| http_msg | target HTTP message |
| msg_parsed_ok | message parsing result |
|
protected |
Consumes payload content in the parser's read buffer.
| http_msg | the HTTP message object to consume content for |
| ec | error_code contains additional information for parsing errors |
|
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 |
|
inlinestaticprotected |
Creates the unique parser error_category_t.
|
inline |
Returns true if there are no more bytes available in the read buffer.
| void staticlib::pion::http_parser::finish | ( | http_message & | http_msg | ) | const |
Finishes parsing an HTTP response message.
| http_msg | the HTTP message object to finish |
| sl::support::tribool staticlib::pion::http_parser::finish_header_parsing | ( | http_message & | http_msg, |
| std::error_code & | ec | ||
| ) |
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 |
| ec | error_code contains additional information for parsing errors |
|
inlineprotectedvirtual |
Called after we have finished parsing the HTTP message headers.
| @param |
|
inline |
Returns the number of bytes read during the last parse operation.
|
inline |
Returns the total number of bytes read while parsing the payload content.
|
inlinestatic |
Returns an instance of parser::error_category_t.
|
inline |
Returns the maximum length for HTTP payload content.
|
inline |
Returns true if parsing headers only.
|
inline |
Returns the raw HTTP headers saved by the parser.
|
inline |
Returns true if the parser is saving raw HTTP header contents.
|
inline |
Returns the total number of bytes read while parsing the HTTP message.
|
staticprotected |
|
inlinestaticprotected |
|
inlinestaticprotected |
| bool staticlib::pion::http_parser::is_parsing_request | ( | ) | const |
Returns true if the parser is being used to parse an HTTP request.
| bool staticlib::pion::http_parser::is_parsing_response | ( | ) | const |
Returns true if the parser is being used to parse an HTTP response.
|
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) |
| http_parser& staticlib::pion::http_parser::operator= | ( | const http_parser & | ) |
Deleted copy assignment operator.
| sl::support::tribool staticlib::pion::http_parser::parse | ( | http_message & | http_msg, |
| std::error_code & | ec | ||
| ) |
Parses an HTTP message including all payload content it might contain.
| http_msg | the HTTP message object to populate from parsing |
| ec | error_code contains additional information for parsing errors |
|
protected |
Parses a chunked HTTP message-body using bytes available in the read buffer.
| chunk_buffers | buffers to be populated from parsing chunked content |
| ec | error_code contains additional information for parsing errors |
|
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 |
|
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 |
|
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 |
| ec | error_code contains additional information for parsing errors |
|
inline |
Controls headers-only parsing (default is disabled; content parsed also)
| b | if true, then the parse() function returns true after headers |
|
static |
Parse key-value pairs out of a multipart/form-data payload content (http://www.ietf.org/rfc/rfc2388.txt)
| dict | dictionary for key-values pairs |
| content_type | value of the content-type HTTP header |
| ptr | points to the start of the encoded data |
| len | length of the encoded data, in bytes |
|
static |
Parse key-value pairs out of a multipart/form-data payload content (http://www.ietf.org/rfc/rfc2388.txt)
| dict | dictionary for key-values pairs |
| content_type | value of the content-type HTTP header |
| form_data | the encoded form data |
|
static |
Parses a URI string.
| uri | the string to parse |
| proto | will be set to the protocol (i.e. "http") |
| host | will be set to the hostname (i.e. "www.cloudmeter.com") |
| port | host port number to use for connection (i.e. 80) |
| path | uri stem or file path |
| query | uri query string |
|
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 |
|
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 |
|
inline |
Resets the parser to its initial state.
|
inline |
Resets the maximum length for HTTP payload content to the default value.
|
inlinestaticprotected |
Sets an error code.
| ec | error code variable to define |
| ev | error value to raise |
|
inline |
Sets the maximum length for HTTP payload content.
| n | maximum length for HTTP payload content |
|
inline |
Defines a callback function to be used for consuming payload content.
| h | a callback function to be used for consuming payload content |
|
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 |
|
inline |
Sets parameter for saving raw HTTP header content.
| b | parameter for saving raw HTTP header content |
|
inline |
Skip parsing all headers and parse payload content only.
| http_msg | the HTTP message object being parsed |
|
protected |
Updates an http::message object with data obtained from parsing headers.
| http_msg | the HTTP message object to populate from parsing |
|
staticprotected |
Maximum length for the name of a cookie name.
|
staticprotected |
Maximum length for the value of a cookie; also used for path and domain.
|
static |
Maximum length for HTTP payload content (for non-streaming server)
|
staticprotected |
Maximum length for an HTTP header name.
|
staticprotected |
Maximum length for an HTTP header value.
|
protected |
Points to the end of the read_buffer (last byte + 1)
|
protected |
Points to the next character to be consumed in the read_buffer.
|
staticprotected |
Maximum length for the request method.
|
staticprotected |
Maximum length for the name of a query string variable.
|
staticprotected |
Maximum length for the query string.
|
staticprotected |
Maximum length for the value of a query string variable.
|
staticprotected |
Maximum length for the resource requested.
|
staticprotected |
Maximum length for response status message.
1.8.1.2