Stores, parses, and manipulates HTTP responses. More...
#include <response.hpp>
Public Types | |
typedef response | type |
typedef lib::shared_ptr< type > | ptr |
Public Member Functions | |
response () | |
size_t | consume (char const *buf, size_t len) |
Process bytes in the input buffer. More... | |
size_t | consume (std::istream &s) |
Process bytes in the input buffer (istream version) More... | |
bool | ready () const |
Returns true if the response is ready. More... | |
bool | headers_ready () const |
Returns true if the response headers are fully parsed. More... | |
std::string | raw () const |
Returns the full raw response. More... | |
void | set_status (status_code::value code) |
Set response status code and message. More... | |
void | set_status (status_code::value code, std::string const &msg) |
Set response status code and message. More... | |
status_code::value | get_status_code () const |
Return the response status code. More... | |
const std::string & | get_status_msg () const |
Return the response status message. More... | |
Public Member Functions inherited from websocketpp::http::parser::parser | |
parser () | |
std::string const & | get_version () const |
Get the HTTP version string. More... | |
void | set_version (std::string const &version) |
Set HTTP parser Version. More... | |
std::string const & | get_header (std::string const &key) const |
Get the value of an HTTP header. More... | |
bool | get_header_as_plist (std::string const &key, parameter_list &out) const |
Extract an HTTP parameter list from a parser header. More... | |
header_list const & | get_headers () const |
Return a list of all HTTP headers. More... | |
void | append_header (std::string const &key, std::string const &val) |
Append a value to an existing HTTP header. More... | |
void | replace_header (std::string const &key, std::string const &val) |
Set a value for an HTTP header, replacing an existing value. More... | |
void | remove_header (std::string const &key) |
Remove a header from the parser. More... | |
std::string const & | get_body () const |
Get HTTP body. More... | |
void | set_body (std::string const &value) |
Set body content. More... | |
size_t | get_max_body_size () const |
Get body size limit. More... | |
void | set_max_body_size (size_t value) |
Set body size limit. More... | |
bool | parse_parameter_list (std::string const &in, parameter_list &out) const |
Extract an HTTP parameter list from a string. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from websocketpp::http::parser::parser | |
void | process_header (std::string::iterator begin, std::string::iterator end) |
Process a header line. More... | |
bool | prepare_body () |
Prepare the parser to begin parsing body data. More... | |
size_t | process_body (char const *buf, size_t len) |
Process body data. More... | |
bool | body_ready () const |
Check if the parser is done parsing the body. More... | |
std::string | raw_headers () const |
Generate and return the HTTP headers as a string. More... | |
Protected Attributes inherited from websocketpp::http::parser::parser | |
std::string | m_version |
header_list | m_headers |
size_t | m_header_bytes |
std::string | m_body |
size_t | m_body_bytes_needed |
size_t | m_body_bytes_max |
body_encoding::value | m_body_encoding |
Stores, parses, and manipulates HTTP responses.
http::response provides the following functionality for working with HTTP responses.
http::response checks for header completeness separately from the full response. Once the header is complete, the Content-Length header is read to determine when to stop reading body bytes. If no Content-Length is present ready() will never return true. It is the responsibility of the caller to consume to determine when the response is complete (ie when the connection terminates, or some other metric).
Definition at line 57 of file response.hpp.
Definition at line 59 of file response.hpp.
typedef lib::shared_ptr<type> websocketpp::http::parser::response::ptr |
Definition at line 60 of file response.hpp.
|
inline |
Definition at line 62 of file response.hpp.
References consume().
|
inline |
Process bytes in the input buffer.
Process up to len bytes from input buffer buf. Returns the number of bytes processed. Bytes left unprocessed means bytes left over after the final header delimiters.
Consume is a streaming processor. It may be called multiple times on one response and the full headers need not be available before processing can begin. If the end of the response was reached during this call to consume the ready flag will be set. Further calls to consume once ready will be ignored.
Consume will throw an http::exception in the case of an error. Typical error reasons include malformed responses, incomplete responses, and max header size being reached.
buf | Pointer to byte buffer |
len | Size of byte buffer |
Definition at line 42 of file response.hpp.
References websocketpp::http::status_code::bad_request, websocketpp::http::parser::parser::get_header(), websocketpp::http::header_delimiter, websocketpp::http::parser::parser::m_header_bytes, websocketpp::http::max_header_size, websocketpp::http::parser::parser::process_header(), and websocketpp::http::status_code::request_header_fields_too_large.
Referenced by BOOST_AUTO_TEST_CASE(), consume(), and response().
|
inline |
Process bytes in the input buffer (istream version)
Process bytes from istream s. Returns the number of bytes processed. Bytes left unprocessed means bytes left over after the final header delimiters.
Consume is a streaming processor. It may be called multiple times on one response and the full headers need not be available before processing can begin. If the end of the response was reached during this call to consume the ready flag will be set. Further calls to consume once ready will be ignored.
Consume will throw an http::exception in the case of an error. Typical error reasons include malformed responses, incomplete responses, and max header size being reached.
buf | Pointer to byte buffer |
len | Size of byte buffer |
Definition at line 139 of file response.hpp.
References consume(), and websocketpp::http::istream_buffer.
|
inline |
Returns true if the response is ready.
Definition at line 116 of file response.hpp.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Returns true if the response headers are fully parsed.
Definition at line 121 of file response.hpp.
References raw(), and set_status().
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Returns the full raw response.
Definition at line 178 of file response.hpp.
References websocketpp::http::parser::parser::get_version(), websocketpp::http::parser::parser::m_body, and websocketpp::http::parser::parser::raw_headers().
Referenced by headers_ready().
|
inline |
Set response status code and message.
Sets the response status code to code
and looks up the corresponding message for standard codes. Non-standard codes will be entered as Unknown use set_status(status_code::value,std::string) overload to set both values explicitly.
code | Code to set |
msg | Message to set |
Definition at line 191 of file response.hpp.
References websocketpp::close::status::get_string().
Referenced by headers_ready(), and set_status().
|
inline |
Set response status code and message.
Sets the response status code and message to independent custom values. use set_status(status_code::value) to set the code and have the standard message be automatically set.
code | Code to set |
msg | Message to set |
Definition at line 197 of file response.hpp.
References websocketpp::http::status_code::bad_request, websocketpp::http::parser::parser::m_body, set_status(), and websocketpp::http::parser::parser::set_version().
|
inline |
Return the response status code.
Definition at line 152 of file response.hpp.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Return the response status message.
Definition at line 157 of file response.hpp.
Referenced by BOOST_AUTO_TEST_CASE().