12 #include <boost/asio.hpp>
13 #include <boost/regex.hpp>
14 #include <boost/logic/tribool.hpp>
15 #include <pion/net/HTTPMessage.hpp>
16 #include <pion/net/HTTPRequest.hpp>
17 #include <pion/net/HTTPParser.hpp>
18 #include <pion/net/TCPConnection.hpp>
26 const boost::regex HTTPMessage::REGEX_ICASE_CHUNKED(
".*chunked.*", boost::regex::icase);
32 boost::system::error_code& ec,
44 return tcp_conn.
write(write_buffers, ec);
48 boost::system::error_code& ec,
52 const bool is_request = (
dynamic_cast<HTTPRequest*
>(
this) != NULL);
55 std::size_t last_bytes_read = 0;
63 const char *read_end_ptr;
65 last_bytes_read = (read_end_ptr - read_ptr);
71 PION_ASSERT(last_bytes_read > 0);
76 bool force_connection_closed =
false;
77 boost::tribool parse_result;
80 parse_result = http_parser.
parse(*
this, ec);
81 if (! boost::indeterminate(parse_result))
break;
85 if (ec || last_bytes_read == 0) {
89 ec = make_error_code(boost::system::errc::io_error);
95 force_connection_closed =
true;
107 if (parse_result ==
false) {
114 if ( http_parser.
eof() ) {
116 tcp_conn.
setLifecycle(TCPConnection::LIFECYCLE_KEEPALIVE);
119 tcp_conn.
setLifecycle(TCPConnection::LIFECYCLE_PIPELINED);
124 const char *read_ptr;
125 const char *read_end_ptr;
138 boost::system::error_code& ec,
bool headers_only)
152 std::size_t bytes_out = 0;
153 for (WriteBuffers::const_iterator i=write_buffers.begin(); i!=write_buffers.end(); ++i) {
154 const char *ptr = boost::asio::buffer_cast<
const char*>(*i);
155 size_t len = boost::asio::buffer_size(*i);
164 boost::system::error_code& ec,
bool headers_only)
171 const bool is_request = (
dynamic_cast<HTTPRequest*
>(
this) != NULL);
176 boost::tribool parse_result;
181 ec = make_error_code(boost::system::errc::io_error);
185 parse_result = http_parser.
parse(*
this, ec);
186 if (! boost::indeterminate(parse_result))
break;
189 if (boost::indeterminate(parse_result)) {
193 ec = make_error_code(boost::system::errc::io_error);
210 if (m_chunk_cache.size() > 0)
211 std::copy(m_chunk_cache.begin(), m_chunk_cache.end(), post_buffer);
std::size_t getTotalBytesRead(void) const
returns the total number of bytes read while parsing the HTTP message
boost::tribool parse(HTTPMessage &http_msg, boost::system::error_code &ec)
bool checkKeepAlive(void) const
returns true if the HTTP connection may be kept alive
bool getKeepAlive(void) const
returns true if the connection should be kept alive
void loadReadPosition(const char *&read_ptr, const char *&read_end_ptr) const
virtual void clear(void)
clears all message data
bool getPipelined(void) const
returns true if the HTTP requests are pipelined
void setLifecycle(LifecycleType t)
sets the lifecycle type for the connection
void concatenateChunks(void)
std::size_t send(TCPConnection &tcp_conn, boost::system::error_code &ec, bool headers_only=false)
std::size_t read(std::istream &in, boost::system::error_code &ec, bool headers_only=false)
void saveReadPosition(const char *read_ptr, const char *read_end_ptr)
std::vector< boost::asio::const_buffer > WriteBuffers
data type for I/O write buffers (these wrap existing data to be sent)
std::size_t read_some(boost::system::error_code &ec)
std::size_t getContentLength(void) const
returns the length of the payload content (in bytes)
std::size_t receive(TCPConnection &tcp_conn, boost::system::error_code &ec, bool headers_only=false)
char * createContentBuffer(void)
void setContentLength(const std::size_t n)
sets the length of the payload content (in bytes)
std::size_t write(std::ostream &out, boost::system::error_code &ec, bool headers_only=false)
void loadReadPosition(const char *&read_ptr, const char *&read_end_ptr) const
std::size_t write(const ConstBufferSequence &buffers, boost::system::error_code &ec)
bool checkPrematureEOF(HTTPMessage &http_msg)
void setReadBuffer(const char *ptr, size_t len)
bool eof(void) const
returns true if there are no more bytes available in the read buffer
void parseHeadersOnly(bool b=true)
void prepareBuffersForSend(WriteBuffers &write_buffers, const bool keep_alive, const bool using_chunks)
ReadBuffer & getReadBuffer(void)
returns the buffer used for reading data from the TCP connection
char * getContent(void)
returns a pointer to the payload content, or NULL if there is none