PionNetworkLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pion::http::reader Class Referenceabstract

#include <reader.hpp>

Inheritance diagram for pion::http::reader:
Collaboration diagram for pion::http::reader:

Public Member Functions

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)
 

Protected Member Functions

 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...
 
virtual void read_bytes (void)=0
 Reads more bytes from the TCP connection. More...
 
virtual void finished_reading (const boost::system::error_code &ec)=0
 Called after we have finished reading/parsing the HTTP message. More...
 
virtual http::messageget_message (void)=0
 Returns a reference to the HTTP message being parsed. More...
 
- Protected Member Functions inherited from pion::http::parser
virtual void finished_parsing_headers (const boost::system::error_code &)
 Called after we have finished parsing the HTTP message headers. More...
 
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)
 

Additional Inherited Members

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

reader: asynchronously reads and parses HTTP messages

Constructor & Destructor Documentation

virtual pion::http::reader::~reader ( )
inlinevirtual
pion::http::reader::reader ( const bool  is_request,
const tcp::connection_ptr tcp_conn 
)
inlineprotected

protected constructor: only derived classes may create objects

Parameters
is_requestif true, the message is parsed as an HTTP request; if false, the message is parsed as an HTTP response
tcp_connTCP connection containing a new message to parse

Member Function Documentation

void pion::http::reader::consume_bytes ( const boost::system::error_code &  read_error,
std::size_t  bytes_read 
)
protected

Consumes bytes that have been read using an HTTP parser

Parameters
read_errorerror status from the last read operation
bytes_readnumber of bytes consumed by the last read operation

References consume_bytes(), pion::http::parser::is_parsing_request(), pion::http::parser::m_logger, PION_LOG_DEBUG, and pion::http::parser::set_read_buffer().

virtual void pion::http::reader::finished_reading ( const boost::system::error_code &  ec)
protectedpure virtual

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

Implemented in pion::http::response_reader, and pion::http::request_reader.

Referenced by consume_bytes().

virtual http::message& pion::http::reader::get_message ( void  )
protectedpure virtual

Returns a reference to the HTTP message being parsed.

Implemented in pion::http::response_reader, and pion::http::request_reader.

Referenced by consume_bytes().

virtual void pion::http::reader::read_bytes ( void  )
protectedpure virtual

Reads more bytes from the TCP connection.

Implemented in pion::http::response_reader, and pion::http::request_reader.

void pion::http::reader::receive ( void  )
void pion::http::reader::set_timeout ( boost::uint32_t  seconds)
inline

sets the maximum number of seconds for read operations


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