staticlib_pion  2.0.2
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Public Member Functions | Protected Member Functions | List of all members
staticlib::pion::http_request Class Reference

Container for HTTP request information. More...

#include <staticlib/pion/http_request.hpp>

Inheritance diagram for staticlib::pion::http_request:
staticlib::pion::http_message

Public Member Functions

 http_request ()
 Constructs a new request object (default constructor)
 http_request (const http_request &)
 Deleted copy constructor.
http_request & operator= (const http_request &)
 Deleted copy-assignment operator.
virtual ~http_request () STATICLIB_NOEXCEPT
 Virtual destructor.
virtual void clear ()
 Clears all request data.
virtual bool is_content_length_implied () const
 The content length of the message can never be implied for requests.
const std::string & get_method () const
 Returns the request method (i.e.
const std::string & get_resource () const
 Returns the resource uri-stem to be delivered (possibly the result of a redirect)
const std::string & get_original_resource () const
 Returns the resource uri-stem originally requested.
const std::string & get_query_string () const
 Returns the uri-query or query string requested.
const std::string & get_query (const std::string &key) const
 Returns a value for the query key if any are defined; otherwise, an empty string.
std::unordered_multimap
< std::string, std::string,
algorithm::ihash,
algorithm::iequal_to > & 
get_queries ()
 Returns the query parameters.
bool has_query (const std::string &key) const
 Returns true if at least one value for the query key is defined.
void set_method (const std::string &str)
 Sets the HTTP request method (i.e.
void set_resource (const std::string &str)
 Sets the resource or uri-stem originally requested.
void change_resource (const std::string &str)
 Changes the resource or uri-stem to be delivered (called as the result of a redirect)
void set_query_string (const std::string &str)
 Sets the uri-query or query string requested.
void add_query (const std::string &key, const std::string &value)
 Adds a value for the query key.
void change_query (const std::string &key, const std::string &value)
 Changes the value of a query key.
void delete_query (const std::string &key)
 Removes all values for a query key.
void use_query_params_for_query_string ()
 Use the query parameters to build a query string for the request.
void use_query_params_for_post_content ()
 Use the query parameters to build POST content for the request.
void set_content (const std::string &value)
 Add content (for POST) from string.
void set_content (const char *value, size_t size)
 Add content (for POST) from buffer of given size; Does nothing if the buffer is invalid or the buffer size is zero.
void set_payload_handler (http_parser::payload_handler_type ph)
 This method should be called from payload_handler_creator to stick payload handler to this request.
template<typename T >
T * get_payload_handler ()
 Access to the wrapped payload handler object.
http_parser::payload_handler_type & get_payload_handler_wrapper ()
 Access to the payload handler wrapper.
void set_request_reader (http_parser *rr)
 Internal method used with payload handlers.
- Public Member Functions inherited from staticlib::pion::http_message
 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.
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 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.

Protected Member Functions

virtual void update_first_line () const
 Updates the string containing the first line for the HTTP message.
virtual void append_cookie_headers ()
 Appends HTTP headers for any cookies defined by the http::message.
- Protected Member Functions inherited from staticlib::pion::http_message
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 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)

Additional Inherited Members

- Public Types inherited from staticlib::pion::http_message
enum  data_status_type { STATUS_NONE, STATUS_TRUNCATED, STATUS_PARTIAL, STATUS_OK }
 Used to cache chunked data. More...
- Static Public Attributes inherited from staticlib::pion::http_message
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
- Static Protected Member Functions inherited from staticlib::pion::http_message
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 inherited from staticlib::pion::http_message
std::string m_first_line
 First line sent in an HTTP message (i.e.

Detailed Description

Container for HTTP request information.

Constructor & Destructor Documentation

staticlib::pion::http_request::http_request ( )
inline

Constructs a new request object (default constructor)

staticlib::pion::http_request::http_request ( const http_request &  )

Deleted copy constructor.

virtual staticlib::pion::http_request::~http_request ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

void staticlib::pion::http_request::add_query ( const std::string &  key,
const std::string &  value 
)
inline

Adds a value for the query key.

Parameters
keyquery key
valueadditional value for this key
virtual void staticlib::pion::http_request::append_cookie_headers ( )
inlineprotectedvirtual

Appends HTTP headers for any cookies defined by the http::message.

Reimplemented from staticlib::pion::http_message.

void staticlib::pion::http_request::change_query ( const std::string &  key,
const std::string &  value 
)
inline

Changes the value of a query key.

Parameters
keyquery key
valuevalue for this key
void staticlib::pion::http_request::change_resource ( const std::string &  str)
inline

Changes the resource or uri-stem to be delivered (called as the result of a redirect)

Parameters
strresource or uri-stem to be delivered
virtual void staticlib::pion::http_request::clear ( )
inlinevirtual

Clears all request data.

Reimplemented from staticlib::pion::http_message.

void staticlib::pion::http_request::delete_query ( const std::string &  key)
inline

Removes all values for a query key.

Parameters
keyquery key
const std::string& staticlib::pion::http_request::get_method ( ) const
inline

Returns the request method (i.e.

GET, POST, PUT)

Returns
request method
const std::string& staticlib::pion::http_request::get_original_resource ( ) const
inline

Returns the resource uri-stem originally requested.

Returns
resource uri-stem originally requested
template<typename T >
T* staticlib::pion::http_request::get_payload_handler ( )
inline

Access to the wrapped payload handler object.

Returns
unwrapped payload handler object
http_parser::payload_handler_type& staticlib::pion::http_request::get_payload_handler_wrapper ( )
inline

Access to the payload handler wrapper.

Returns
payload handler
std::unordered_multimap<std::string, std::string, algorithm::ihash, algorithm::iequal_to>& staticlib::pion::http_request::get_queries ( )
inline

Returns the query parameters.

Returns
query parameters multimap
const std::string& staticlib::pion::http_request::get_query ( const std::string &  key) const
inline

Returns a value for the query key if any are defined; otherwise, an empty string.

Parameters
keyquery key
Returns
value for the query key if any are defined; otherwise, an empty string
const std::string& staticlib::pion::http_request::get_query_string ( ) const
inline

Returns the uri-query or query string requested.

Returns
uri-query or query string requested
const std::string& staticlib::pion::http_request::get_resource ( ) const
inline

Returns the resource uri-stem to be delivered (possibly the result of a redirect)

Returns
resource uri-stem to be delivered
bool staticlib::pion::http_request::has_query ( const std::string &  key) const
inline

Returns true if at least one value for the query key is defined.

Parameters
keyquery key
Returns
true if at least one value for the query key is defined
virtual bool staticlib::pion::http_request::is_content_length_implied ( void  ) const
inlinevirtual

The content length of the message can never be implied for requests.

Returns
false

Implements staticlib::pion::http_message.

http_request& staticlib::pion::http_request::operator= ( const http_request &  )

Deleted copy-assignment operator.

void staticlib::pion::http_request::set_content ( const std::string &  value)
inline

Add content (for POST) from string.

Parameters
valuePOST content

Reimplemented from staticlib::pion::http_message.

void staticlib::pion::http_request::set_content ( const char *  value,
size_t  size 
)
inline

Add content (for POST) from buffer of given size; Does nothing if the buffer is invalid or the buffer size is zero.

void staticlib::pion::http_request::set_method ( const std::string &  str)
inline

Sets the HTTP request method (i.e.

GET, POST, PUT)

Parameters
strrequest method
void staticlib::pion::http_request::set_payload_handler ( http_parser::payload_handler_type  ph)
inline

This method should be called from payload_handler_creator to stick payload handler to this request.

Parameters
phpayload handler
void staticlib::pion::http_request::set_query_string ( const std::string &  str)
inline

Sets the uri-query or query string requested.

Parameters
struri-query or query string requested
void staticlib::pion::http_request::set_request_reader ( http_parser *  rr)
inline

Internal method used with payload handlers.

void staticlib::pion::http_request::set_resource ( const std::string &  str)
inline

Sets the resource or uri-stem originally requested.

virtual void staticlib::pion::http_request::update_first_line ( ) const
inlineprotectedvirtual

Updates the string containing the first line for the HTTP message.

Implements staticlib::pion::http_message.

void staticlib::pion::http_request::use_query_params_for_post_content ( )
inline

Use the query parameters to build POST content for the request.

void staticlib::pion::http_request::use_query_params_for_query_string ( )
inline

Use the query parameters to build a query string for the request.


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