12 #include <boost/asio.hpp>
13 #include <boost/assert.hpp>
14 #include <boost/regex.hpp>
15 #include <boost/logic/tribool.hpp>
16 #include <pion/http/message.hpp>
17 #include <pion/http/request.hpp>
18 #include <pion/http/parser.hpp>
19 #include <pion/tcp/connection.hpp>
28 const boost::regex message::REGEX_ICASE_CHUNKED(
".*chunked.*", boost::regex::icase);
34 boost::system::error_code& ec,
bool headers_only)
45 return tcp_conn.
write(write_buffers, ec);
49 boost::system::error_code& ec,
52 std::size_t last_bytes_read = 0;
60 const char *read_end_ptr;
62 last_bytes_read = (read_end_ptr - read_ptr);
68 BOOST_ASSERT(last_bytes_read > 0);
73 bool force_connection_closed =
false;
74 boost::tribool parse_result;
77 parse_result = http_parser.
parse(*
this, ec);
78 if (! boost::indeterminate(parse_result))
break;
82 if (ec || last_bytes_read == 0) {
86 ec = make_error_code(boost::system::errc::io_error);
92 force_connection_closed =
true;
104 if (parse_result ==
false) {
111 if ( http_parser.
eof() ) {
113 tcp_conn.
set_lifecycle(tcp::connection::LIFECYCLE_KEEPALIVE);
116 tcp_conn.
set_lifecycle(tcp::connection::LIFECYCLE_PIPELINED);
121 const char *read_ptr;
122 const char *read_end_ptr;
133 const char *read_ptr;
134 const char *read_end_ptr;
144 boost::system::error_code& ec,
146 std::size_t max_content_length)
148 http::parser http_parser(dynamic_cast<http::request*>(
this) != NULL);
151 return receive(tcp_conn, ec, http_parser);
155 boost::system::error_code& ec,
bool headers_only)
169 std::size_t bytes_out = 0;
170 for (write_buffers_t::const_iterator i=write_buffers.begin(); i!=write_buffers.end(); ++i) {
171 const char *ptr = boost::asio::buffer_cast<
const char*>(*i);
172 size_t len = boost::asio::buffer_size(*i);
181 boost::system::error_code& ec,
189 boost::tribool parse_result;
194 ec = make_error_code(boost::system::errc::io_error);
198 parse_result = http_parser.
parse(*
this, ec);
199 if (! boost::indeterminate(parse_result))
break;
202 if (boost::indeterminate(parse_result)) {
206 ec = make_error_code(boost::system::errc::io_error);
220 boost::system::error_code& ec,
222 std::size_t max_content_length)
224 http::parser http_parser(dynamic_cast<http::request*>(
this) != NULL);
227 return read(in, ec, http_parser);
234 if (m_chunk_cache.size() > 0)
235 std::copy(m_chunk_cache.begin(), m_chunk_cache.end(), post_buffer);
bool check_keep_alive(void) const
returns true if the HTTP connection may be kept alive
void save_read_pos(const char *read_ptr, const char *read_end_ptr)
bool get_keep_alive(void) const
returns true if the connection should be kept alive
virtual void clear(void)
clears all message data
void load_read_pos(const char *&read_ptr, const char *&read_end_ptr) const
void set_max_content_length(std::size_t n)
sets the maximum length for HTTP payload content
size_t get_content_length(void) const
returns the length of the payload content (in bytes)
void concatenate_chunks(void)
bool get_pipelined(void) const
returns true if the HTTP requests are pipelined
bool eof(void) const
returns true if there are no more bytes available in the read buffer
void set_content_length(size_t n)
sets the length of the payload content (in bytes)
std::size_t send(tcp::connection &tcp_conn, boost::system::error_code &ec, bool headers_only=false)
std::size_t read(std::istream &in, boost::system::error_code &ec, parser &http_parser)
std::size_t read_some(boost::system::error_code &ec)
read_buffer_type & get_read_buffer(void)
returns the buffer used for reading data from the TCP connection
boost::tribool parse(http::message &http_msg, boost::system::error_code &ec)
bool get_parse_headers_only(void)
returns true if parsing headers only
std::size_t write(std::ostream &out, boost::system::error_code &ec, bool headers_only=false)
void load_read_pos(const char *&read_ptr, const char *&read_end_ptr) const
std::size_t get_total_bytes_read(void) const
returns the total number of bytes read while parsing the HTTP message
void set_lifecycle(lifecycle_type t)
sets the lifecycle type for the connection
std::size_t receive(tcp::connection &tcp_conn, boost::system::error_code &ec, parser &http_parser)
char * create_content_buffer(void)
char * get_content(void)
returns a pointer to the payload content, or empty string if there is none
void prepare_buffers_for_send(write_buffers_t &write_buffers, const bool keep_alive, const bool using_chunks)
std::size_t write(const ConstBufferSequence &buffers, boost::system::error_code &ec)
bool check_premature_eof(http::message &http_msg)
std::vector< boost::asio::const_buffer > write_buffers_t
data type for I/O write buffers (these wrap existing data to be sent)
void parse_headers_only(bool b=true)
void set_read_buffer(const char *ptr, size_t len)