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_response Class Reference

Container for HTTP response information. More...

#include <staticlib/pion/http_response.hpp>

Inheritance diagram for staticlib::pion::http_response:
staticlib::pion::http_message

Public Member Functions

 http_response (const http_request &http_request_ptr)
 Constructs a new response object for a particular request.
 http_response (const http_response &http_response)
 Copy constructor.
virtual ~http_response () STATICLIB_NOEXCEPT
 Virtual destructor.
virtual void clear ()
 Clears all response data.
virtual bool is_content_length_implied () const
 The content length may be implied for certain types of responses.
void update_request_info (const http_request &http_request)
 Updates HTTP request information for the response object (use this if the response cannot be constructed using the request)
void set_status_code (unsigned int n)
 Sets the HTTP response status code.
void set_status_message (const std::string &msg)
 Sets the HTTP response status message.
unsigned int get_status_code () const
 Returns the HTTP response status code.
const std::string & get_status_message () const
 Returns the HTTP response status message.
bool is_body_allowed () const
 Returns true if this response can have a body.
void set_cookie (const std::string &name, const std::string &value)
 Sets a cookie by adding a Set-Cookie header (see RFC 2109) the cookie will be discarded by the user-agent when it closes.
void set_cookie (const std::string &name, const std::string &value, const std::string &path)
 Sets a cookie by adding a Set-Cookie header (see RFC 2109) the cookie will be discarded by the user-agent when it closes.
void set_cookie (const std::string &name, const std::string &value, const std::string &path, const unsigned long max_age)
 Sets a cookie by adding a Set-Cookie header (see RFC 2109)
void set_cookie (const std::string &name, const std::string &value, const unsigned long max_age)
 Sets a cookie by adding a Set-Cookie header (see RFC 2109)
void delete_cookie (const std::string &name)
 Deletes cookie called name by adding a Set-Cookie header (cookie has no path)
void delete_cookie (const std::string &name, const std::string &path)
 Deletes cookie called name by adding a Set-Cookie header (cookie has a path)
void set_last_modified (const unsigned long t)
 Sets the time that the response was last modified (Last-Modified)
- 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.
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.

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 response information.

Constructor & Destructor Documentation

staticlib::pion::http_response::http_response ( const http_request &  http_request_ptr)
inline

Constructs a new response object for a particular request.

Parameters
http_request_ptrthe request that this is responding to
staticlib::pion::http_response::http_response ( const http_response &  http_response)
inline

Copy constructor.

Parameters
http_responseanother instance
virtual staticlib::pion::http_response::~http_response ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

virtual void staticlib::pion::http_response::append_cookie_headers ( )
inlineprotectedvirtual

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

Reimplemented from staticlib::pion::http_message.

virtual void staticlib::pion::http_response::clear ( )
inlinevirtual

Clears all response data.

Reimplemented from staticlib::pion::http_message.

void staticlib::pion::http_response::delete_cookie ( const std::string &  name)
inline

Deletes cookie called name by adding a Set-Cookie header (cookie has no path)

Parameters
namecookie name

Reimplemented from staticlib::pion::http_message.

void staticlib::pion::http_response::delete_cookie ( const std::string &  name,
const std::string &  path 
)
inline

Deletes cookie called name by adding a Set-Cookie header (cookie has a path)

Parameters
namecookie name
pathcookie path
unsigned int staticlib::pion::http_response::get_status_code ( ) const
inline

Returns the HTTP response status code.

Returns
HTTP response status code
const std::string& staticlib::pion::http_response::get_status_message ( ) const
inline

Returns the HTTP response status message.

Returns
bool staticlib::pion::http_response::is_body_allowed ( ) const
inline

Returns true if this response can have a body.

Returns
true if this response can have a body
virtual bool staticlib::pion::http_response::is_content_length_implied ( void  ) const
inlinevirtual

The content length may be implied for certain types of responses.

Returns
whether content length implied

Implements staticlib::pion::http_message.

void staticlib::pion::http_response::set_cookie ( const std::string &  name,
const std::string &  value 
)
inline

Sets a cookie by adding a Set-Cookie header (see RFC 2109) the cookie will be discarded by the user-agent when it closes.

Parameters
namethe name of the cookie
valuethe value of the cookie
void staticlib::pion::http_response::set_cookie ( const std::string &  name,
const std::string &  value,
const std::string &  path 
)
inline

Sets a cookie by adding a Set-Cookie header (see RFC 2109) the cookie will be discarded by the user-agent when it closes.

Parameters
namethe name of the cookie
valuethe value of the cookie
paththe path of the cookie
void staticlib::pion::http_response::set_cookie ( const std::string &  name,
const std::string &  value,
const std::string &  path,
const unsigned long  max_age 
)
inline

Sets a cookie by adding a Set-Cookie header (see RFC 2109)

Parameters
namethe name of the cookie
valuethe value of the cookie
paththe path of the cookie
max_agethe life of the cookie, in seconds (0 = discard)
void staticlib::pion::http_response::set_cookie ( const std::string &  name,
const std::string &  value,
const unsigned long  max_age 
)
inline

Sets a cookie by adding a Set-Cookie header (see RFC 2109)

Parameters
namethe name of the cookie
valuethe value of the cookie
max_agethe life of the cookie, in seconds (0 = discard)
void staticlib::pion::http_response::set_last_modified ( const unsigned long  t)

Sets the time that the response was last modified (Last-Modified)

Parameters
tlast modified time
void staticlib::pion::http_response::set_status_code ( unsigned int  n)
inline

Sets the HTTP response status code.

Parameters
nHTTP response status code
void staticlib::pion::http_response::set_status_message ( const std::string &  msg)
inline

Sets the HTTP response status message.

Parameters
msgHTTP response status message
virtual void staticlib::pion::http_response::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_response::update_request_info ( const http_request &  http_request)
inline

Updates HTTP request information for the response object (use this if the response cannot be constructed using the request)

Parameters
http_requestthe request that this is responding to

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