10 #include <boost/asio.hpp>
11 #include <boost/logic/tribool.hpp>
12 #include <pion/net/HTTPReader.hpp>
13 #include <pion/net/HTTPRequest.hpp>
22 const boost::uint32_t HTTPReader::DEFAULT_READ_TIMEOUT = 10;
29 if (m_tcp_conn->getPipelined()) {
31 m_tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_CLOSE);
36 m_tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_CLOSE);
37 readBytesWithTimeout();
42 std::size_t bytes_read)
46 m_timer_ptr->cancel();
52 handleReadError(read_error);
56 PION_LOG_DEBUG(
m_logger,
"Read " << bytes_read <<
" bytes from HTTP "
60 setReadBuffer(m_tcp_conn->getReadBuffer().data(), bytes_read);
76 boost::system::error_code ec;
91 m_tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_KEEPALIVE);
94 m_tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_PIPELINED);
101 PION_LOG_DEBUG(
m_logger,
"HTTP pipelined "
106 m_tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_CLOSE);
112 }
else if (result ==
false) {
114 m_tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_CLOSE);
119 readBytesWithTimeout();
123 void HTTPReader::readBytesWithTimeout(
void)
125 if (m_read_timeout > 0) {
126 m_timer_ptr.reset(
new TCPTimer(m_tcp_conn));
127 m_timer_ptr->start(m_read_timeout);
128 }
else if (m_timer_ptr) {
134 void HTTPReader::handleReadError(
const boost::system::error_code& read_error)
137 m_tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_CLOSE);
141 boost::system::error_code ec;
148 if (read_error == boost::asio::error::operation_aborted) {
152 <<
" parsing aborted (shutting down)");
155 <<
" parsing aborted (" << read_error.message() <<
')');
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)
virtual void readBytes(void)=0
Reads more bytes from the TCP connection.
std::size_t gcount(void) const
returns the number of bytes read during the last parse operation
void consumeBytes(void)
Consumes bytes that have been read using an HTTP parser.
virtual void finishedReading(const boost::system::error_code &ec)=0
Called after we have finished reading/parsing the HTTP message.
void setIsValid(bool b=true)
sets whether or not the message is valid
std::size_t bytes_available(void) const
returns the number of bytes available in the read buffer
PionLogger m_logger
primary logging interface used by this class
const char * m_read_ptr
points to the next character to be consumed in the read_buffer
the following enables use of the lock-free cache
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
virtual HTTPMessage & getMessage(void)=0
Returns a reference to the HTTP message being parsed.
const char * m_read_end_ptr
points to the end of the read_buffer (last byte + 1)
void receive(void)
Incrementally reads & parses the HTTP message.
bool isParsingRequest(void) const
returns true if the parser is being used to parse an HTTP request