![]() |
staticlib_pion
2.0.2
|
Base container for HTTP messages. More...
#include <staticlib/pion/http_message.hpp>
Classes | |
| class | content_buffer_t |
| A simple helper class used to manage a fixed-size payload content buffer. More... | |
| struct | receive_error_t |
| Data type for library errors returned during receive() operations. More... | |
Public Types | |
| enum | data_status_type { STATUS_NONE, STATUS_TRUNCATED, STATUS_PARTIAL, STATUS_OK } |
| Used to cache chunked data. More... | |
Public Member Functions | |
| http_message () | |
| Constructs a new HTTP message object. | |
| http_message (const http_message &http_msg) | |
| Copy constructor. | |
| http_message & | operator= (const http_message &http_msg) |
| Assignment operator. | |
| virtual | ~http_message () STATICLIB_NOEXCEPT |
| Virtual destructor. | |
| virtual void | clear () |
| Clears all message data. | |
| virtual bool | is_content_length_implied (void) const =0 |
| Should return true if the content length can be implied without headers. | |
| bool | is_valid () const |
| Returns true if the message is valid. | |
| bool | get_chunks_supported () const |
| Returns true if chunked transfer encodings are supported. | |
| const asio::ip::address & | get_remote_ip () const |
| Returns IP address of the remote endpoint. | |
| uint16_t | get_version_major () const |
| Returns the major HTTP version number. | |
| uint16_t | get_version_minor () const |
| Returns the minor HTTP version number. | |
| std::string | get_version_string () const |
| Returns a string representation of the HTTP version (i.e. | |
| size_t | get_content_length () const |
| Returns the length of the payload content (in bytes) | |
| bool | is_chunked (void) const |
| Returns true if the message content is chunked. | |
| bool | is_content_buffer_allocated () const |
| Returns true if buffer for content is allocated. | |
| std::size_t | get_content_buffer_size () const |
| Returns size of allocated buffer. | |
| char * | get_content () |
| Returns a pointer to the payload content, or empty string if there is none. | |
| const char * | get_content () const |
| Returns a const pointer to the payload content, or empty string if there is none. | |
| std::vector< char > & | get_chunk_cache () |
| Returns a reference to the chunk cache. | |
| const std::string & | get_header (const std::string &key) const |
| Returns a value for the header if any are defined; otherwise, an empty string. | |
| bool | has_header_value (const std::string &key, const std::string &value) const |
| headers_type & | get_headers () |
| Returns a reference to the HTTP headers multimap. | |
| bool | has_header (const std::string &key) const |
| Returns true if at least one value for the header is defined. | |
| const std::string & | get_cookie (const std::string &key) const |
| Returns a value for the cookie if any are defined; otherwise, an empty string since cookie names are insensitive, key should use lowercase alpha chars. | |
| headers_type & | get_cookies () |
| Returns the cookie parameters. | |
| bool | has_cookie (const std::string &key) const |
| Returns true if at least one value for the cookie is defined since cookie names are insensitive, key should use lowercase alpha chars. | |
| void | add_cookie (const std::string &key, const std::string &value) |
| Adds a value for the cookie since cookie names are insensitive, key should use lowercase alpha chars. | |
| void | change_cookie (const std::string &key, const std::string &value) |
| Changes the value of a cookie since cookie names are insensitive, key should use lowercase alpha chars. | |
| void | delete_cookie (const std::string &key) |
| Removes all values for a cookie since cookie names are insensitive, key should use lowercase alpha chars. | |
| const std::string & | get_first_line () const |
| Returns a string containing the first line for the HTTP message. | |
| bool | has_missing_packets () const |
| Returns true if there were missing packets. | |
| void | set_missing_packets (bool newVal) |
| Set to true when missing packets detected. | |
| bool | has_data_after_missing_packets () const |
| Returns true if more data seen after the missing packets. | |
| void | set_data_after_missing_packet (bool newVal) |
| Sets data seen after the missing packets flag. | |
| void | set_is_valid (bool b=true) |
| Sets whether or not the message is valid. | |
| void | set_chunks_supported (bool b) |
| Set to true if chunked transfer encodings are supported. | |
| void | set_remote_ip (const asio::ip::address &ip) |
| Sets IP address of the remote endpoint. | |
| void | set_version_major (const uint16_t n) |
| Sets the major HTTP version number. | |
| void | set_version_minor (const uint16_t n) |
| Sets the minor HTTP version number. | |
| void | set_content_length (size_t n) |
| Sets the length of the payload content (in bytes) | |
| void | set_do_not_send_content_length () |
| If called, the content-length will not be sent in the HTTP headers. | |
| data_status_type | get_status () const |
| Return the data receival status. | |
| void | set_status (data_status_type newVal) |
| Sets data receival status. | |
| void | update_content_length_using_header () |
| Sets the length of the payload content using the Content-Length header. | |
| void | update_transfer_encoding_using_header () |
| Sets the transfer coding using the Transfer-Encoding header. | |
| char * | create_content_buffer () |
| Creates a payload content buffer of size m_content_length and returns a pointer to the new buffer (memory is managed by message class) | |
| void | set_content (const std::string &content) |
| Resets payload content to match the value of a string. | |
| void | clear_content () |
| Clears payload content buffer. | |
| void | set_content_type (const std::string &type) |
| Sets the content type for the message payload. | |
| void | add_header (const std::string &key, const std::string &value) |
| Adds a value for the HTTP header named key. | |
| void | change_header (const std::string &key, const std::string &value) |
| Changes the value for the HTTP header named key. | |
| void | delete_header (const std::string &key) |
| Removes all values for the HTTP header named key. | |
| bool | check_keep_alive () const |
| Returns true if the HTTP connection may be kept alive. | |
| void | prepare_buffers_for_send (std::vector< asio::const_buffer > &write_buffers, const bool keep_alive, const bool using_chunks) |
| Initializes a vector of write buffers with the HTTP message information. | |
| void | concatenate_chunks () |
| Pieces together all the received chunks. | |
Static Public Attributes | |
| static const std::string | STRING_EMPTY |
| static const std::string | STRING_CRLF |
| static const std::string | STRING_HTTP_VERSION |
| static const std::string | HEADER_NAME_VALUE_DELIMITER |
| static const std::string | COOKIE_NAME_VALUE_DELIMITER |
| static const std::string | HEADER_HOST |
| static const std::string | HEADER_COOKIE |
| static const std::string | HEADER_SET_COOKIE |
| static const std::string | HEADER_CONNECTION |
| static const std::string | HEADER_CONTENT_TYPE |
| static const std::string | HEADER_CONTENT_LENGTH |
| static const std::string | HEADER_CONTENT_LOCATION |
| static const std::string | HEADER_CONTENT_ENCODING |
| static const std::string | HEADER_CONTENT_DISPOSITION |
| static const std::string | HEADER_LAST_MODIFIED |
| static const std::string | HEADER_IF_MODIFIED_SINCE |
| static const std::string | HEADER_TRANSFER_ENCODING |
| static const std::string | HEADER_LOCATION |
| static const std::string | HEADER_AUTHORIZATION |
| static const std::string | HEADER_REFERER |
| static const std::string | HEADER_USER_AGENT |
| static const std::string | HEADER_X_FORWARDED_FOR |
| static const std::string | HEADER_CLIENT_IP |
| static const std::string | CONTENT_TYPE_HTML |
| static const std::string | CONTENT_TYPE_TEXT |
| static const std::string | CONTENT_TYPE_XML |
| static const std::string | CONTENT_TYPE_URLENCODED |
| static const std::string | CONTENT_TYPE_MULTIPART_FORM_DATA |
| static const std::string | REQUEST_METHOD_HEAD |
| static const std::string | REQUEST_METHOD_GET |
| static const std::string | REQUEST_METHOD_PUT |
| static const std::string | REQUEST_METHOD_POST |
| static const std::string | REQUEST_METHOD_DELETE |
| static const std::string | REQUEST_METHOD_OPTIONS |
| static const std::string | RESPONSE_MESSAGE_OK |
| static const std::string | RESPONSE_MESSAGE_CREATED |
| static const std::string | RESPONSE_MESSAGE_ACCEPTED |
| static const std::string | RESPONSE_MESSAGE_NO_CONTENT |
| static const std::string | RESPONSE_MESSAGE_FOUND |
| static const std::string | RESPONSE_MESSAGE_UNAUTHORIZED |
| static const std::string | RESPONSE_MESSAGE_FORBIDDEN |
| static const std::string | RESPONSE_MESSAGE_NOT_FOUND |
| static const std::string | RESPONSE_MESSAGE_METHOD_NOT_ALLOWED |
| static const std::string | RESPONSE_MESSAGE_NOT_MODIFIED |
| static const std::string | RESPONSE_MESSAGE_BAD_REQUEST |
| static const std::string | RESPONSE_MESSAGE_SERVER_ERROR |
| static const std::string | RESPONSE_MESSAGE_NOT_IMPLEMENTED |
| static const std::string | RESPONSE_MESSAGE_CONTINUE |
| static const unsigned int | RESPONSE_CODE_OK |
| static const unsigned int | RESPONSE_CODE_CREATED |
| static const unsigned int | RESPONSE_CODE_ACCEPTED |
| static const unsigned int | RESPONSE_CODE_NO_CONTENT |
| static const unsigned int | RESPONSE_CODE_FOUND |
| static const unsigned int | RESPONSE_CODE_UNAUTHORIZED |
| static const unsigned int | RESPONSE_CODE_FORBIDDEN |
| static const unsigned int | RESPONSE_CODE_NOT_FOUND |
| static const unsigned int | RESPONSE_CODE_METHOD_NOT_ALLOWED |
| static const unsigned int | RESPONSE_CODE_NOT_MODIFIED |
| static const unsigned int | RESPONSE_CODE_BAD_REQUEST |
| static const unsigned int | RESPONSE_CODE_SERVER_ERROR |
| static const unsigned int | RESPONSE_CODE_NOT_IMPLEMENTED |
| static const unsigned int | RESPONSE_CODE_CONTINUE |
| static const std::string | RESPONSE_FULLMESSAGE_100_CONTINUE |
Protected Member Functions | |
| std::string | make_query_string (const std::unordered_multimap< std::string, std::string, algorithm::ihash, algorithm::iequal_to > &query_params) |
| Builds an HTTP query string from a collection of query parameters. | |
| std::string | make_set_cookie_header (const std::string &name, const std::string &value, const std::string &path, const bool has_max_age=false, const unsigned long max_age=0) |
| Creates a "Set-Cookie" header. | |
| void | prepare_headers_for_send (const bool keep_alive, const bool using_chunks) |
| Prepares HTTP headers for a send operation. | |
| void | append_headers (std::vector< asio::const_buffer > &write_buffers) |
| Appends the message's HTTP headers to a vector of write buffers. | |
| void | append_cookie_headers () |
| Appends HTTP headers for any cookies defined by the http::message. | |
| void | clear_first_line () const |
| Erases the string containing the first line for the HTTP message (it will be updated the next time get_first_line() is called) | |
| virtual void | update_first_line () const =0 |
| Updates the string containing the first line for the HTTP message. | |
Static Protected Member Functions | |
| static const std::string & | get_value (const headers_type &dict, const std::string &key) |
| Returns the first value in a dictionary if key is found; or an empty string if no values are found. | |
| static void | change_value (headers_type &dict, const std::string &key, const std::string &value) |
| Changes the value for a dictionary key. | |
| static void | delete_value (headers_type &dict, const std::string &key) |
| Deletes all values for a key. | |
Protected Attributes | |
| std::string | m_first_line |
| First line sent in an HTTP message (i.e. | |
Base container for HTTP messages.
|
inline |
Constructs a new HTTP message object.
|
inline |
Copy constructor.
|
inlinevirtual |
Virtual destructor.
|
inline |
Adds a value for the cookie since cookie names are insensitive, key should use lowercase alpha chars.
| key | cookie name |
| value | cookie value |
|
inline |
Adds a value for the HTTP header named key.
| key | header name |
| value | header value |
|
inlineprotected |
Appends HTTP headers for any cookies defined by the http::message.
Reimplemented in staticlib::pion::http_request, and staticlib::pion::http_response.
|
inlineprotected |
Appends the message's HTTP headers to a vector of write buffers.
| write_buffers | the buffers to append HTTP headers into |
|
inline |
Changes the value of a cookie since cookie names are insensitive, key should use lowercase alpha chars.
| key | cookie name |
| value | cookie value |
|
inline |
Changes the value for the HTTP header named key.
| key | header name |
| value | header value |
|
inlinestaticprotected |
Changes the value for a dictionary key.
Adds the key if it does not already exist. If multiple values exist for the key, they will be removed and only the new value will remain.
| dict | the dictionary object to update |
| key | the key to change the value for |
| value | the value to assign to the key |
|
inline |
Returns true if the HTTP connection may be kept alive.
|
inlinevirtual |
Clears all message data.
Reimplemented in staticlib::pion::http_request, and staticlib::pion::http_response.
|
inline |
Clears payload content buffer.
|
inlineprotected |
Erases the string containing the first line for the HTTP message (it will be updated the next time get_first_line() is called)
|
inline |
Pieces together all the received chunks.
|
inline |
Creates a payload content buffer of size m_content_length and returns a pointer to the new buffer (memory is managed by message class)
|
inline |
Removes all values for a cookie since cookie names are insensitive, key should use lowercase alpha chars.
| key | cookie name |
Reimplemented in staticlib::pion::http_response.
|
inline |
Removes all values for the HTTP header named key.
| key | header name |
|
inlinestaticprotected |
Deletes all values for a key.
| dict | the dictionary object to update |
| key | the key to delete |
|
inline |
Returns a reference to the chunk cache.
|
inline |
Returns true if chunked transfer encodings are supported.
|
inline |
Returns a pointer to the payload content, or empty string if there is none.
|
inline |
Returns a const pointer to the payload content, or empty string if there is none.
|
inline |
Returns size of allocated buffer.
|
inline |
Returns the length of the payload content (in bytes)
|
inline |
Returns a value for the cookie if any are defined; otherwise, an empty string since cookie names are insensitive, key should use lowercase alpha chars.
| key | cookie name |
|
inline |
Returns the cookie parameters.
|
inline |
Returns a string containing the first line for the HTTP message.
|
inline |
Returns a value for the header if any are defined; otherwise, an empty string.
|
inline |
Returns a reference to the HTTP headers multimap.
|
inline |
Returns IP address of the remote endpoint.
|
inline |
Return the data receival status.
|
inlinestaticprotected |
Returns the first value in a dictionary if key is found; or an empty string if no values are found.
| dict | the dictionary to search for key |
| key | the key to search for |
|
inline |
Returns the major HTTP version number.
|
inline |
Returns the minor HTTP version number.
|
inline |
Returns a string representation of the HTTP version (i.e.
"HTTP/1.1")
|
inline |
Returns true if at least one value for the cookie is defined since cookie names are insensitive, key should use lowercase alpha chars.
| key | cookie name |
|
inline |
Returns true if more data seen after the missing packets.
|
inline |
Returns true if at least one value for the header is defined.
| key | header name |
|
inline |
|
inline |
Returns true if there were missing packets.
|
inline |
Returns true if the message content is chunked.
|
inline |
Returns true if buffer for content is allocated.
|
pure virtual |
Should return true if the content length can be implied without headers.
Implemented in staticlib::pion::http_request, and staticlib::pion::http_response.
|
inline |
Returns true if the message is valid.
|
inlineprotected |
Builds an HTTP query string from a collection of query parameters.
| query_params | query parameters |
|
inlineprotected |
Creates a "Set-Cookie" header.
| name | the name of the cookie |
| value | the value of the cookie |
| path | the path of the cookie |
| has_max_age | true if the max_age value should be set |
| max_age | the life of the cookie, in seconds (0 = discard) |
|
inline |
Assignment operator.
| http_msg | source instance |
|
inline |
Initializes a vector of write buffers with the HTTP message information.
| write_buffers | vector of write buffers to initialize |
| keep_alive | true if the connection should be kept alive |
| using_chunks | true if the payload content will be sent in chunks |
|
inlineprotected |
Prepares HTTP headers for a send operation.
| keep_alive | true if the connection should be kept alive |
| using_chunks | true if the payload content will be sent in chunks |
|
inline |
Set to true if chunked transfer encodings are supported.
| b | chunked transfer encodings are supported flag |
|
inline |
Resets payload content to match the value of a string.
| content | payload content |
Reimplemented in staticlib::pion::http_request.
|
inline |
Sets the length of the payload content (in bytes)
| n | length of the payload content (in bytes) |
|
inline |
Sets the content type for the message payload.
| type | content type |
|
inline |
Sets data seen after the missing packets flag.
| newVal | data seen after the missing packets flag |
|
inline |
If called, the content-length will not be sent in the HTTP headers.
|
inline |
Sets whether or not the message is valid.
| b | is-valid flag |
|
inline |
Set to true when missing packets detected.
| newVal | missing packets flag |
|
inline |
Sets IP address of the remote endpoint.
| ip | IP address of the remote endpoint |
|
inline |
Sets data receival status.
| newVal | data receival status |
|
inline |
Sets the major HTTP version number.
| n | major HTTP version number |
|
inline |
Sets the minor HTTP version number.
| n | minor HTTP version number |
|
inline |
Sets the length of the payload content using the Content-Length header.
|
protectedpure virtual |
Updates the string containing the first line for the HTTP message.
Implemented in staticlib::pion::http_request, and staticlib::pion::http_response.
|
inline |
Sets the transfer coding using the Transfer-Encoding header.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
mutableprotected |
First line sent in an HTTP message (i.e.
"GET / HTTP/1.1" for request, or "HTTP/1.1 200 OK" for response)
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
1.8.1.2