WebSocket++ 0.8.3-dev
C++ websocket client/server library
Loading...
Searching...
No Matches
websocketpp::http::parser::response Class Reference

Stores, parses, and manipulates HTTP responses. More...

#include <response.hpp>

Inheritance diagram for websocketpp::http::parser::response:
websocketpp::http::parser::parser

Public Types

typedef response type
typedef lib::shared_ptr< type > ptr

Public Member Functions

size_t consume (char const *buf, size_t len, lib::error_code &ec)
 Process bytes in the input buffer.
size_t consume (std::istream &s, lib::error_code &ec)
 Process bytes in the input buffer (istream version).
bool ready () const
 Returns true if the response is ready.
bool headers_ready () const
 Returns true if the response headers are fully parsed.
std::string raw () const
 Returns the full raw response.
lib::error_code set_status (status_code::value code)
 Set response status code and message.
lib::error_code set_status (status_code::value code, std::string const &msg)
 Set response status code and message.
status_code::value get_status_code () const
 Return the response status code.
const std::string & get_status_msg () const
 Return the response status message.
Public Member Functions inherited from websocketpp::http::parser::parser
std::string const & get_version () const
 Get the HTTP version string.
lib::error_code set_version (std::string const &version)
 Set HTTP parser Version.
std::string const & get_header (std::string const &key) const
 Get the value of an HTTP header.
bool get_header_as_plist (std::string const &key, parameter_list &out) const
 Extract an HTTP parameter list from a parser header.
header_list const & get_headers () const
 Return a list of all HTTP headers.
lib::error_code append_header (std::string const &key, std::string const &val)
 Append a value to an existing HTTP header.
lib::error_code replace_header (std::string const &key, std::string const &val)
 Set a value for an HTTP header, replacing an existing value.
lib::error_code remove_header (std::string const &key)
 Remove a header from the parser.
std::string const & get_body () const
 Get HTTP body.
lib::error_code set_body (std::string const &value)
 Set body content.
size_t get_max_body_size () const
 Get body size limit.
void set_max_body_size (size_t value)
 Set body size limit.
bool parse_parameter_list (std::string const &in, parameter_list &out) const
 Extract an HTTP parameter list from a string.

Additional Inherited Members

Protected Member Functions inherited from websocketpp::http::parser::parser
lib::error_code process_header (std::string::iterator begin, std::string::iterator end)
 Process a header line.
bool prepare_body (lib::error_code &ec)
 Prepare the parser to begin parsing body data.
size_t process_body (char const *buf, size_t len, lib::error_code &ec)
 Process body data.
bool body_ready () const
 Check if the parser is done parsing the body.
std::string raw_headers () const
 Generate and return the HTTP headers as a string.
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

Detailed Description

Stores, parses, and manipulates HTTP responses.

http::response provides the following functionality for working with HTTP responses.

  • Initialize response via manually setting each element
  • Initialize response via reading raw bytes and parsing
  • Once initialized, access individual parsed elements
  • Once initialized, read entire response as raw bytes

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.

Member Typedef Documentation

◆ ptr

typedef lib::shared_ptr<type> websocketpp::http::parser::response::ptr

Definition at line 60 of file response.hpp.

◆ type

typedef response websocketpp::http::parser::response::type

Definition at line 59 of file response.hpp.

Constructor & Destructor Documentation

◆ response()

websocketpp::http::parser::response::response ( )
inline

Definition at line 62 of file response.hpp.

Member Function Documentation

◆ consume() [1/2]

size_t websocketpp::http::parser::response::consume ( char const * buf,
size_t len,
lib::error_code & ec )
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.

As of 0.9.0, consume will return a status code describing the output of the operation. Earlier versions threw an http::exception. The status code will be zero/default constructed on success and non-zero on error. Typical error reasons include malformed responses, incomplete responses, and max header size being reached.

Since
0.9.0 Added ec parameter
Parameters
[in]bufPointer to byte buffer
[in]lenSize of byte buffer
[out]ecA status code describing the outcome of the operation.
Returns
Number of bytes processed.

Definition at line 42 of file response.hpp.

◆ consume() [2/2]

size_t websocketpp::http::parser::response::consume ( std::istream & s,
lib::error_code & ec )
inline

Process bytes in the input buffer (istream version).

Process bytes from istream s. Returns the number of bytes processed.

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.

As of 0.9.0, consume will return a status code describing the output of the operation. Earlier versions threw an http::exception. The status code will be zero/default constructed on success and non-zero on error. Typical error reasons include malformed responses, incomplete responses, and max header size being reached.

WARNING: If not all the bytes were needed to complete the HTTP request those bytes will still be removed from the istream and discarded. If this happens an error istream_overread will be returned. This means that the response read was successful but that some unrelated data was lost. If you don't care about these bytes you can ignore the error.

If there is an HTTP processing error and an istream overread in the same call only the HTTP processing error will be returned.

If you might need bytes after the header in the istream you should NOT use this wrapper and instead read data out of the istream directly and pass it to consume(char const *, size_t, lib::error_code). This method allows you to retain overread data.

Deprecated
0.9.0 This overload is dangerous in that it can overread the stream and there isn't a good way to recover bytes lost this way. As of 0.9.0 an error is raised when this situation happens, but generally, it would be better for the calling application to read the stream itself and call consume(char const *, size_t, lib::error_code) instead which provides a better method of identifying and recovering from overreads.
Since
0.9.0 Added ec parameter
Parameters
spointer to an istream to read from
[out]ecA status code describing the outcome of the operation.
Returns
Number of bytes processed.

Definition at line 189 of file response.hpp.

◆ get_status_code()

status_code::value websocketpp::http::parser::response::get_status_code ( ) const
inline

Return the response status code.

Definition at line 185 of file response.hpp.

◆ get_status_msg()

const std::string & websocketpp::http::parser::response::get_status_msg ( ) const
inline

Return the response status message.

Definition at line 190 of file response.hpp.

◆ headers_ready()

bool websocketpp::http::parser::response::headers_ready ( ) const
inline

Returns true if the response headers are fully parsed.

Definition at line 149 of file response.hpp.

◆ raw()

std::string websocketpp::http::parser::response::raw ( ) const
inline

Returns the full raw response.

Definition at line 246 of file response.hpp.

◆ ready()

bool websocketpp::http::parser::response::ready ( ) const
inline

Returns true if the response is ready.

Note
will never return true if the content length header is not present

Definition at line 144 of file response.hpp.

◆ set_status() [1/2]

lib::error_code websocketpp::http::parser::response::set_status ( status_code::value code)
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.

Since
0.9.0 Added return value
Parameters
codeCode to set
Returns
A status code describing the outcome of the operation.

Definition at line 259 of file response.hpp.

◆ set_status() [2/2]

lib::error_code websocketpp::http::parser::response::set_status ( status_code::value code,
std::string const & msg )
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.

Since
0.9.0 Added return value
Parameters
codeCode to set
msgMessage to set
Returns
A status code describing the outcome of the operation.

Definition at line 269 of file response.hpp.


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