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

Base HTTP parser. More...

#include <parser.hpp>

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

Public Member Functions

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.

Protected Member Functions

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

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

Base HTTP parser.

Includes methods and data elements common to all types of HTTP messages such as headers, versions, bodies, etc.

Definition at line 398 of file parser.hpp.

Constructor & Destructor Documentation

◆ parser()

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

Definition at line 400 of file parser.hpp.

Member Function Documentation

◆ append_header()

lib::error_code websocketpp::http::parser::parser::append_header ( std::string const & key,
std::string const & val )
inline

Append a value to an existing HTTP header.

This method will set the value of the HTTP header key with the indicated value. If a header with the name key already exists, val will be appended to the existing value.

Note: per HTTP specs header values are compared case insensitively.

Todo
Should there be any restrictions on which keys are allowed?
See also
replace_header
Since
0.9.0 (return value added, exceptions removed)
Parameters
[in]keyThe name/key of the header to append to.
[in]valThe value to append.
Returns
A status code describing the outcome of the operation.

Definition at line 72 of file parser.hpp.

◆ body_ready()

bool websocketpp::http::parser::parser::body_ready ( ) const
inlineprotected

Check if the parser is done parsing the body.

Behavior before a call to prepare_body is undefined.

Since
0.5.0
Returns
True if the message body has been completed loaded.

Definition at line 618 of file parser.hpp.

◆ get_body()

std::string const & websocketpp::http::parser::parser::get_body ( ) const
inline

Get HTTP body.

Gets the body of the HTTP object

Returns
The body of the HTTP message.

Definition at line 515 of file parser.hpp.

◆ get_header()

std::string const & websocketpp::http::parser::parser::get_header ( std::string const & key) const
inline

Get the value of an HTTP header.

Note: per HTTP specs header values are compared case insensitively.

Parameters
[in]keyThe name/key of the header to get.
Returns
The value associated with the given HTTP header key.

Definition at line 48 of file parser.hpp.

◆ get_header_as_plist()

bool websocketpp::http::parser::parser::get_header_as_plist ( std::string const & key,
parameter_list & out ) const
inline

Extract an HTTP parameter list from a parser header.

If the header requested doesn't exist or exists and is empty the parameter list is valid (but empty).

Parameters
[in]keyThe name/key of the HTTP header to use as input.
[out]outThe parameter list to store extracted parameters in.
Returns
Whether or not the input was a valid parameter list.

Definition at line 60 of file parser.hpp.

◆ get_headers()

header_list const & websocketpp::http::parser::parser::get_headers ( ) const
inline

Return a list of all HTTP headers.

Return a list of all HTTP headers

Since
0.8.0
Returns
A list of all HTTP headers

Definition at line 211 of file parser.hpp.

◆ get_max_body_size()

size_t websocketpp::http::parser::parser::get_max_body_size ( ) const
inline

Get body size limit.

Retrieves the maximum number of bytes to parse & buffer before canceling a request.

Since
0.5.0
Returns
The maximum length of a message body.

Definition at line 542 of file parser.hpp.

◆ get_version()

std::string const & websocketpp::http::parser::parser::get_version ( ) const
inline

Get the HTTP version string.

Returns
The version string for this parser

Definition at line 410 of file parser.hpp.

◆ parse_parameter_list()

bool websocketpp::http::parser::parser::parse_parameter_list ( std::string const & in,
parameter_list & out ) const
inline

Extract an HTTP parameter list from a string.

Parameters
[in]inThe input string.
[out]outThe parameter list to store extracted parameters in.
Returns
Whether or not the input was a valid parameter list.

Definition at line 131 of file parser.hpp.

◆ prepare_body()

bool websocketpp::http::parser::parser::prepare_body ( lib::error_code & ec)
inlineprotected

Prepare the parser to begin parsing body data.

Inspects headers to determine if the message has a body that needs to be read. If so, sets up the necessary state, otherwise returns false. If this method returns true and loading the message body is desired call process_body until it returns zero bytes or an error.

Must not be called until after all headers have been processed.

Since
0.5.0 (no parameters)
0.9.0 (ec parameter added, exceptions removed)
Parameters
[out]ecA status code describing the outcome of the operation.
Returns
True if more bytes are needed to load the body, false otherwise.

Definition at line 143 of file parser.hpp.

◆ process_body()

size_t websocketpp::http::parser::parser::process_body ( char const * buf,
size_t len,
lib::error_code & ec )
inlineprotected

Process body data.

Parses body data.

Since
0.5.0
0.9.0 (ec parameter added, exceptions removed)
Parameters
[in]beginAn iterator to the beginning of the sequence.
[in]endAn iterator to the end of the sequence.
[out]ecA status code describing the outcome of the operation.
Returns
The number of bytes processed

Definition at line 172 of file parser.hpp.

◆ process_header()

lib::error_code websocketpp::http::parser::parser::process_header ( std::string::iterator begin,
std::string::iterator end )
inlineprotected

Process a header line.

Since
0.9.0 (return value added, exceptions removed)
Parameters
[in]beginAn iterator to the beginning of the sequence.
[in]endAn iterator to the end of the sequence.
Returns
A status code describing the outcome of the operation.

Definition at line 191 of file parser.hpp.

◆ raw_headers()

std::string websocketpp::http::parser::parser::raw_headers ( ) const
inlineprotected

Generate and return the HTTP headers as a string.

Each headers will be followed by the \r
sequence including the last one. A second \r
sequence (blank header) is not appended by this method

Returns
The HTTP headers as a string.

Definition at line 215 of file parser.hpp.

◆ remove_header()

lib::error_code websocketpp::http::parser::parser::remove_header ( std::string const & key)
inline

Remove a header from the parser.

Removes the header entirely from the parser. This is different than setting the value of the header to blank.

Note: per HTTP specs header values are compared case insensitively.

Since
0.9.0 (return value added)
Parameters
[in]keyThe name/key of the header to remove.
Returns
A status code describing the outcome of the operation.

Definition at line 98 of file parser.hpp.

◆ replace_header()

lib::error_code websocketpp::http::parser::parser::replace_header ( std::string const & key,
std::string const & val )
inline

Set a value for an HTTP header, replacing an existing value.

This method will set the value of the HTTP header key with the indicated value. If a header with the name key already exists, val will replace the existing value.

Note: per HTTP specs header values are compared case insensitively.

See also
append_header
Since
0.9.0 (return value added)
Parameters
[in]keyThe name/key of the header to append to.
[in]valThe value to append.
Returns
A status code describing the outcome of the operation.

Definition at line 87 of file parser.hpp.

◆ set_body()

lib::error_code websocketpp::http::parser::parser::set_body ( std::string const & value)
inline

Set body content.

Set the body content of the HTTP response to the parameter string. Note set_body will also set the Content-Length HTTP header to the appropriate value. If you want the Content-Length header to be something else, do so via replace_header("Content-Length") after calling set_body()

Since
0.9.0 (return value added)
Parameters
valueString data to include as the body content.
Returns
A status code describing the outcome of the operation.

Definition at line 108 of file parser.hpp.

◆ set_max_body_size()

void websocketpp::http::parser::parser::set_max_body_size ( size_t value)
inline

Set body size limit.

Set the maximum number of bytes to parse and buffer before canceling a request.

Since
0.5.0
Parameters
valueThe size to set the max body length to.

Definition at line 555 of file parser.hpp.

◆ set_version()

lib::error_code websocketpp::http::parser::parser::set_version ( std::string const & version)
inline

Set HTTP parser Version.

Input should be in format: HTTP/x.y where x and y are positive integers.

Todo
Does this method need any validation?
Parameters
[in]versionThe value to set the HTTP version to.
Returns
A status code describing the outcome of the operation.

Definition at line 41 of file parser.hpp.

Member Data Documentation

◆ m_body

std::string websocketpp::http::parser::parser::m_body
protected

Definition at line 636 of file parser.hpp.

◆ m_body_bytes_max

size_t websocketpp::http::parser::parser::m_body_bytes_max
protected

Definition at line 638 of file parser.hpp.

◆ m_body_bytes_needed

size_t websocketpp::http::parser::parser::m_body_bytes_needed
protected

Definition at line 637 of file parser.hpp.

◆ m_body_encoding

body_encoding::value websocketpp::http::parser::parser::m_body_encoding
protected

Definition at line 639 of file parser.hpp.

◆ m_header_bytes

size_t websocketpp::http::parser::parser::m_header_bytes
protected

Definition at line 634 of file parser.hpp.

◆ m_headers

header_list websocketpp::http::parser::parser::m_headers
protected

Definition at line 632 of file parser.hpp.

◆ m_version

std::string websocketpp::http::parser::parser::m_version
protected

Definition at line 631 of file parser.hpp.


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