NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
websocketpp::http::parser::parser Class Reference

Base HTTP parser. More...

#include <parser.hpp>

Inheritance diagram for websocketpp::http::parser::parser:
Collaboration diagram for websocketpp::http::parser::parser:

Public Member Functions

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

Protected Member Functions

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

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

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

Definition at line 400 of file parser.hpp.

Member Function Documentation

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.

References websocketpp::http::parser::state::version.

Referenced by BOOST_AUTO_TEST_CASE(), websocketpp::http::parser::request::raw(), websocketpp::http::parser::response::raw(), and websocketpp::http::parser::request::raw_head().

void 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.

Definition at line 41 of file parser.hpp.

References m_version, and websocketpp::http::parser::state::version.

Referenced by BOOST_AUTO_TEST_CASE(), websocketpp::http::parser::response::set_status(), and websocketpp::http::parser::request::set_uri().

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

Get the value of an HTTP header.

Todo:
Make this method case insensitive.
Parameters
[in]keyThe name/key of the header to get.
Returns
The value associated with the given HTTP header key.

Definition at line 45 of file parser.hpp.

References websocketpp::http::empty_header, and m_headers.

Referenced by append_header(), BOOST_AUTO_TEST_CASE(), websocketpp::http::parser::request::consume(), websocketpp::http::parser::response::consume(), websocketpp::processor::hybi08< config >::get_origin(), and prepare_body().

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 55 of file parser.hpp.

References m_headers, and parse_parameter_list().

void 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.

Todo:

Make this method case insensitive.

Should there be any restrictions on which keys are allowed?

Exception free varient

See also
replace_header
Parameters
[in]keyThe name/key of the header to append to.
[in]valThe value to append.

Definition at line 67 of file parser.hpp.

References websocketpp::http::status_code::bad_request, get_header(), websocketpp::http::is_not_token_char(), and m_headers.

Referenced by process_header().

void 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.

Todo:

Make this method case insensitive.

Should there be any restrictions on which keys are allowed?

Exception free varient

See also
append_header
Parameters
[in]keyThe name/key of the header to append to.
[in]valThe value to append.

Definition at line 81 of file parser.hpp.

References m_headers.

Referenced by BOOST_AUTO_TEST_CASE(), and set_body().

void 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.

Todo:
Make this method case insensitive.
Parameters
[in]keyThe name/key of the header to remove.

Definition at line 87 of file parser.hpp.

References m_headers.

Referenced by BOOST_AUTO_TEST_CASE(), and set_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 495 of file parser.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

void 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()

Parameters
valueString data to include as the body content.

Definition at line 91 of file parser.hpp.

References m_body, remove_header(), and replace_header().

Referenced by BOOST_AUTO_TEST_CASE().

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 519 of file parser.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

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 532 of file parser.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

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 107 of file parser.hpp.

References websocketpp::http::parser::extract_parameters().

Referenced by get_header_as_plist().

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

Process a header line.

Todo:
Update this method to be exception free.
Parameters
[in]beginAn iterator to the beginning of the sequence.
[in]endAn iterator to the end of the sequence.

Definition at line 161 of file parser.hpp.

References append_header(), websocketpp::http::status_code::bad_request, websocketpp::http::header_separator, and websocketpp::http::parser::strip_lws().

Referenced by websocketpp::http::parser::request::consume(), and websocketpp::http::parser::response::consume().

bool websocketpp::http::parser::parser::prepare_body ( )
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
Returns
True if more bytes are needed to load the body, false otherwise.

Definition at line 119 of file parser.hpp.

References get_header(), m_body_bytes_max, m_body_bytes_needed, m_body_encoding, websocketpp::http::parser::body_encoding::plain, and websocketpp::http::status_code::request_entity_too_large.

Referenced by websocketpp::http::parser::request::consume().

size_t websocketpp::http::parser::parser::process_body ( char const *  buf,
size_t  len 
)
inlineprotected

Process body data.

Parses body data.

Since
0.5.0
Parameters
[in]beginAn iterator to the beginning of the sequence.
[in]endAn iterator to the end of the sequence.
Returns
The number of bytes processed

Definition at line 145 of file parser.hpp.

References websocketpp::http::parser::body_encoding::chunked, websocketpp::http::status_code::internal_server_error, m_body, m_body_bytes_needed, m_body_encoding, and websocketpp::http::parser::body_encoding::plain.

Referenced by websocketpp::http::parser::request::consume().

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 589 of file parser.hpp.

Referenced by websocketpp::http::parser::request::consume().

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
sequence including the last one. A second
sequence (blank header) is not appended by this method

Returns
The HTTP headers as a string.

Definition at line 179 of file parser.hpp.

References m_headers.

Referenced by websocketpp::http::parser::request::raw(), websocketpp::http::parser::response::raw(), and websocketpp::http::parser::request::raw_head().

Member Data Documentation

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

Definition at line 602 of file parser.hpp.

Referenced by set_version().

header_list websocketpp::http::parser::parser::m_headers
protected
size_t websocketpp::http::parser::parser::m_header_bytes
protected
std::string websocketpp::http::parser::parser::m_body
protected
size_t websocketpp::http::parser::parser::m_body_bytes_needed
protected
size_t websocketpp::http::parser::parser::m_body_bytes_max
protected

Definition at line 609 of file parser.hpp.

Referenced by prepare_body().

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

Definition at line 610 of file parser.hpp.

Referenced by prepare_body(), and process_body().


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