pion  5.0.6
Public Member Functions | Protected Member Functions | List of all members
pion::http::reader Class Referenceabstract

#include <reader.hpp>

Inherits pion::http::parser.

Inherited by pion::http::request_reader, and pion::http::response_reader.

Public Member Functions

void receive (void)
 Incrementally reads & parses the HTTP message.
 
tcp::connection_ptr & get_connection (void)
 returns a shared pointer to the TCP connection
 
void set_timeout (boost::uint32_t seconds)
 sets the maximum number of seconds for read operations
 
- 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
 
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
 
bool eof (void) const
 returns true if there are no more bytes available in the read buffer
 
std::size_t bytes_available (void) const
 returns the number of bytes available in the read buffer
 
std::size_t gcount (void) const
 returns the number of bytes read during the last parse operation
 
std::size_t get_total_bytes_read (void) const
 returns the total number of bytes read while parsing the HTTP message
 
std::size_t get_content_bytes_read (void) const
 returns the total number of bytes read while parsing the payload content
 
std::size_t get_max_content_length (void) const
 returns the maximum length for HTTP payload content
 
const std::string & get_raw_headers (void) const
 returns the raw HTTP headers saved by the parser
 
bool get_save_raw_headers (void) const
 returns true if the parser is saving raw HTTP header contents
 
bool get_parse_headers_only (void)
 returns true if parsing headers only
 
bool is_parsing_request (void) const
 returns true if the parser is being used to parse an HTTP request
 
bool is_parsing_response (void) const
 returns true if the parser is being used to parse an HTTP response
 
void set_payload_handler (payload_handler_t &h)
 defines a callback function to be used for consuming payload content
 
void set_max_content_length (std::size_t n)
 sets the maximum length for HTTP payload content
 
void reset_max_content_length (void)
 resets the maximum length for HTTP payload content to the default value
 
void set_save_raw_headers (bool b)
 sets parameter for saving raw HTTP header content
 
void set_logger (logger log_ptr)
 sets the logger to be used
 
logger get_logger (void)
 returns the logger currently in use
 
boost::tribool finish_header_parsing (http::message &http_msg, boost::system::error_code &ec)
 

Protected Member Functions

 reader (const bool is_request, 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.
 
virtual void read_bytes (void)=0
 Reads more bytes from the TCP connection.
 
virtual void finished_reading (const boost::system::error_code &ec)=0
 Called after we have finished reading/parsing the HTTP message.
 
virtual http::messageget_message (void)=0
 Returns a reference to the HTTP message being parsed.
 
- Protected Member Functions inherited from pion::http::parser
virtual void finished_parsing_headers (const boost::system::error_code &ec)
 Called after we have finished parsing the HTTP message headers.
 
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
 
typedef boost::function2< void, const char *, std::size_t > payload_handler_t
 callback type used to consume payload content
 
- 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
 
- Static Public Attributes inherited from pion::http::parser
static const std::size_t DEFAULT_CONTENT_MAX = 1024 * 1024
 maximum length for HTTP payload content
 
- 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
 
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
 
const bool m_is_request
 true if the message is an HTTP request; false if it is an HTTP response
 
const char * m_read_ptr
 points to the next character to be consumed in the read_buffer
 
const char * m_read_end_ptr
 points to the end of the read_buffer (last byte + 1)
 
- Static Protected Attributes inherited from pion::http::parser
static const boost::uint32_t STATUS_MESSAGE_MAX = 1024
 maximum length for response status message
 
static const boost::uint32_t METHOD_MAX = 1024
 maximum length for the request method
 
static const boost::uint32_t RESOURCE_MAX = 256 * 1024
 maximum length for the resource requested
 
static const boost::uint32_t QUERY_STRING_MAX = 1024 * 1024
 maximum length for the query string
 
static const boost::uint32_t HEADER_NAME_MAX = 1024
 maximum length for an HTTP header name
 
static const boost::uint32_t HEADER_VALUE_MAX = 1024 * 1024
 maximum length for an HTTP header value
 
static const boost::uint32_t QUERY_NAME_MAX = 1024
 maximum length for the name of a query string variable
 
static const boost::uint32_t QUERY_VALUE_MAX = 1024 * 1024
 maximum length for the value of a query string variable
 
static const boost::uint32_t COOKIE_NAME_MAX = 1024
 maximum length for the name of a cookie name
 
static const boost::uint32_t COOKIE_VALUE_MAX = 1024 * 1024
 maximum length for the value of a cookie; also used for path and domain
 

Detailed Description

reader: asynchronously reads and parses HTTP messages

Definition at line 28 of file reader.hpp.

Constructor & Destructor Documentation

pion::http::reader::reader ( const bool  is_request,
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

Definition at line 55 of file reader.hpp.

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

Definition at line 41 of file http_reader.cpp.

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


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