PionNetworkLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pion::http::request_reader Class Reference

#include <request_reader.hpp>

Inheritance diagram for pion::http::request_reader:
Collaboration diagram for pion::http::request_reader:

Public Types

typedef boost::function3< void,
http::request_ptr,
tcp::connection_ptr, const
boost::system::error_code & > 
finished_handler_t
 function called after the HTTP message has been parsed More...
 
- Public Types inherited from pion::http::parser
enum  error_value_t {
  ERROR_METHOD_CHAR = 1, ERROR_METHOD_SIZE, ERROR_URI_CHAR, ERROR_URI_SIZE,
  ERROR_QUERY_CHAR, ERROR_QUERY_SIZE, ERROR_VERSION_EMPTY, ERROR_VERSION_CHAR,
  ERROR_STATUS_EMPTY, ERROR_STATUS_CHAR, ERROR_HEADER_CHAR, ERROR_HEADER_NAME_SIZE,
  ERROR_HEADER_VALUE_SIZE, ERROR_INVALID_CONTENT_LENGTH, ERROR_CHUNK_CHAR, ERROR_MISSING_CHUNK_DATA,
  ERROR_MISSING_HEADER_DATA, ERROR_MISSING_TOO_MUCH_CONTENT
}
 class-specific error code values More...
 
typedef boost::function2< void,
const char *, std::size_t > 
payload_handler_t
 callback type used to consume payload content More...
 

Public Member Functions

virtual ~request_reader ()
 
void set_headers_parsed_callback (finished_handler_t &h)
 sets a function to be called after HTTP headers have been parsed More...
 
- Public Member Functions inherited from pion::http::reader
virtual ~reader ()
 
void receive (void)
 Incrementally reads & parses the HTTP message. More...
 
tcp::connection_ptrget_connection (void)
 returns a shared pointer to the TCP connection More...
 
void set_timeout (boost::uint32_t seconds)
 sets the maximum number of seconds for read operations More...
 
- Public Member Functions inherited from pion::http::parser
 parser (const bool is_request, std::size_t max_content_length=DEFAULT_CONTENT_MAX)
 
virtual ~parser ()
 default destructor More...
 
boost::tribool parse (http::message &http_msg, boost::system::error_code &ec)
 
boost::tribool parse_missing_data (http::message &http_msg, std::size_t len, boost::system::error_code &ec)
 
void finish (http::message &http_msg) const
 
void set_read_buffer (const char *ptr, size_t len)
 
void load_read_pos (const char *&read_ptr, const char *&read_end_ptr) const
 
bool check_premature_eof (http::message &http_msg)
 
void parse_headers_only (bool b=true)
 
void skip_header_parsing (http::message &http_msg)
 
void reset (void)
 resets the parser to its initial state More...
 
bool eof (void) const
 returns true if there are no more bytes available in the read buffer More...
 
std::size_t bytes_available (void) const
 returns the number of bytes available in the read buffer More...
 
std::size_t gcount (void) const
 returns the number of bytes read during the last parse operation More...
 
std::size_t get_total_bytes_read (void) const
 returns the total number of bytes read while parsing the HTTP message More...
 
std::size_t get_content_bytes_read (void) const
 returns the total number of bytes read while parsing the payload content More...
 
std::size_t get_max_content_length (void) const
 returns the maximum length for HTTP payload content More...
 
const std::string & get_raw_headers (void) const
 returns the raw HTTP headers saved by the parser More...
 
bool get_save_raw_headers (void) const
 returns true if the parser is saving raw HTTP header contents More...
 
bool get_parse_headers_only (void)
 returns true if parsing headers only More...
 
bool is_parsing_request (void) const
 returns true if the parser is being used to parse an HTTP request More...
 
bool is_parsing_response (void) const
 returns true if the parser is being used to parse an HTTP response More...
 
void set_payload_handler (payload_handler_t &h)
 defines a callback function to be used for consuming payload content More...
 
void set_max_content_length (std::size_t n)
 sets the maximum length for HTTP payload content More...
 
void reset_max_content_length (void)
 resets the maximum length for HTTP payload content to the default value More...
 
void set_save_raw_headers (bool b)
 sets parameter for saving raw HTTP header content More...
 
void set_logger (logger log_ptr)
 sets the logger to be used More...
 
logger get_logger (void)
 returns the logger currently in use More...
 
boost::tribool finish_header_parsing (http::message &http_msg, boost::system::error_code &ec)
 

Static Public Member Functions

static boost::shared_ptr
< request_reader
create (const tcp::connection_ptr &tcp_conn, finished_handler_t handler)
 
- Static Public Member Functions inherited from pion::http::parser
static bool parse_uri (const std::string &uri, std::string &proto, std::string &host, boost::uint16_t &port, std::string &path, std::string &query)
 
static bool parse_url_encoded (ihash_multimap &dict, const char *ptr, const std::size_t len)
 
static bool parse_multipart_form_data (ihash_multimap &dict, const std::string &content_type, const char *ptr, const std::size_t len)
 
static bool parse_cookie_header (ihash_multimap &dict, const char *ptr, const std::size_t len, bool set_cookie_header)
 
static bool parse_cookie_header (ihash_multimap &dict, const std::string &cookie_header, bool set_cookie_header)
 
static bool parse_url_encoded (ihash_multimap &dict, const std::string &query)
 
static bool parse_multipart_form_data (ihash_multimap &dict, const std::string &content_type, const std::string &form_data)
 
static bool parse_forwarded_for (const std::string &header, std::string &public_ip)
 
static error_category_tget_error_category (void)
 returns an instance of parser::error_category_t More...
 

Protected Member Functions

 request_reader (const tcp::connection_ptr &tcp_conn, finished_handler_t handler)
 
virtual void read_bytes (void)
 Reads more bytes from the TCP connection. More...
 
virtual void finished_parsing_headers (const boost::system::error_code &ec)
 Called after we have finished parsing the HTTP message headers. More...
 
virtual void finished_reading (const boost::system::error_code &ec)
 Called after we have finished reading/parsing the HTTP message. More...
 
virtual http::messageget_message (void)
 Returns a reference to the HTTP message being parsed. More...
 
- Protected Member Functions inherited from pion::http::reader
 reader (const bool is_request, const tcp::connection_ptr &tcp_conn)
 
void consume_bytes (const boost::system::error_code &read_error, std::size_t bytes_read)
 
void consume_bytes (void)
 Consumes bytes that have been read using an HTTP parser. More...
 
- Protected Member Functions inherited from pion::http::parser
boost::tribool parse_headers (http::message &http_msg, boost::system::error_code &ec)
 
void update_message_with_header_data (http::message &http_msg) const
 
boost::tribool parse_chunks (http::message::chunk_cache_t &chunk_buffers, boost::system::error_code &ec)
 
boost::tribool consume_content (http::message &http_msg, boost::system::error_code &ec)
 
std::size_t consume_content_as_next_chunk (http::message::chunk_cache_t &chunk_buffers)
 

Protected Attributes

http::request_ptr m_http_msg
 The new HTTP message container being created. More...
 
finished_handler_t m_finished
 function called after the HTTP message has been parsed More...
 
finished_handler_t m_parsed_headers
 function called after the HTTP message headers have been parsed More...
 
- Protected Attributes inherited from pion::http::parser
logger m_logger
 primary logging interface used by this class More...
 
const bool m_is_request
 true if the message is an HTTP request; false if it is an HTTP response More...
 
const char * m_read_ptr
 points to the next character to be consumed in the read_buffer More...
 
const char * m_read_end_ptr
 points to the end of the read_buffer (last byte + 1) More...
 

Additional Inherited Members

- Static Public Attributes inherited from pion::http::parser
static const std::size_t DEFAULT_CONTENT_MAX = 1024 * 1024
 maximum length for HTTP payload content More...
 
- Static Protected Member Functions inherited from pion::http::parser
static void compute_msg_status (http::message &http_msg, bool msg_parsed_ok)
 
static void set_error (boost::system::error_code &ec, error_value_t ev)
 
static void create_error_category (void)
 creates the unique parser error_category_t More...
 
static bool is_char (int c)
 
static bool is_control (int c)
 
static bool is_special (int c)
 
static bool is_digit (int c)
 
static bool is_hex_digit (int c)
 
static bool is_cookie_attribute (const std::string &name, bool set_cookie_header)
 
- Static Protected Attributes inherited from pion::http::parser
static const boost::uint32_t STATUS_MESSAGE_MAX = 1024
 maximum length for response status message More...
 
static const boost::uint32_t METHOD_MAX = 1024
 maximum length for the request method More...
 
static const boost::uint32_t RESOURCE_MAX = 256 * 1024
 maximum length for the resource requested More...
 
static const boost::uint32_t QUERY_STRING_MAX = 1024 * 1024
 maximum length for the query string More...
 
static const boost::uint32_t HEADER_NAME_MAX = 1024
 maximum length for an HTTP header name More...
 
static const boost::uint32_t HEADER_VALUE_MAX = 1024 * 1024
 maximum length for an HTTP header value More...
 
static const boost::uint32_t QUERY_NAME_MAX = 1024
 maximum length for the name of a query string variable More...
 
static const boost::uint32_t QUERY_VALUE_MAX = 1024 * 1024
 maximum length for the value of a query string variable More...
 
static const boost::uint32_t COOKIE_NAME_MAX = 1024
 maximum length for the name of a cookie name More...
 
static const boost::uint32_t COOKIE_VALUE_MAX = 1024 * 1024
 maximum length for the value of a cookie; also used for path and domain More...
 

Detailed Description

request_reader: asynchronously reads and parses HTTP requests

Member Typedef Documentation

typedef boost::function3<void, http::request_ptr, tcp::connection_ptr, const boost::system::error_code&> pion::http::request_reader::finished_handler_t

function called after the HTTP message has been parsed

Constructor & Destructor Documentation

virtual pion::http::request_reader::~request_reader ( )
inlinevirtual
pion::http::request_reader::request_reader ( const tcp::connection_ptr tcp_conn,
finished_handler_t  handler 
)
inlineprotected

protected constructor restricts creation of objects (use create())

Parameters
tcp_connTCP connection containing a new message to parse
handlerfunction called after the message has been parsed

References m_http_msg, PION_GET_LOGGER, and pion::http::parser::set_logger().

Referenced by create().

Member Function Documentation

static boost::shared_ptr<request_reader> pion::http::request_reader::create ( const tcp::connection_ptr tcp_conn,
finished_handler_t  handler 
)
inlinestatic

creates new request_reader objects

Parameters
tcp_connTCP connection containing a new message to parse
handlerfunction called after the message has been parsed

References request_reader().

Referenced by pion::http::server::handle_connection().

virtual void pion::http::request_reader::finished_parsing_headers ( const boost::system::error_code &  ec)
inlineprotectedvirtual

Called after we have finished parsing the HTTP message headers.

Reimplemented from pion::http::parser.

References pion::http::reader::get_connection(), m_http_msg, and m_parsed_headers.

virtual void pion::http::request_reader::finished_reading ( const boost::system::error_code &  ec)
inlineprotectedvirtual

Called after we have finished reading/parsing the HTTP message.

Implements pion::http::reader.

References pion::http::reader::get_connection(), m_finished, and m_http_msg.

virtual http::message& pion::http::request_reader::get_message ( void  )
inlineprotectedvirtual

Returns a reference to the HTTP message being parsed.

Implements pion::http::reader.

References m_http_msg.

virtual void pion::http::request_reader::read_bytes ( void  )
inlineprotectedvirtual

Reads more bytes from the TCP connection.

Implements pion::http::reader.

References pion::http::reader::consume_bytes(), and pion::http::reader::get_connection().

void pion::http::request_reader::set_headers_parsed_callback ( finished_handler_t h)
inline

sets a function to be called after HTTP headers have been parsed

References m_parsed_headers.

Member Data Documentation

finished_handler_t pion::http::request_reader::m_finished
protected

function called after the HTTP message has been parsed

Referenced by finished_reading().

http::request_ptr pion::http::request_reader::m_http_msg
protected

The new HTTP message container being created.

Referenced by finished_parsing_headers(), finished_reading(), get_message(), and request_reader().

finished_handler_t pion::http::request_reader::m_parsed_headers
protected

function called after the HTTP message headers have been parsed

Referenced by finished_parsing_headers(), and set_headers_parsed_callback().


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