10 #ifndef __PION_HTTPREQUESTWRITER_HEADER__
11 #define __PION_HTTPREQUESTWRITER_HEADER__
13 #include <boost/asio.hpp>
14 #include <boost/bind.hpp>
15 #include <boost/noncopyable.hpp>
16 #include <boost/shared_ptr.hpp>
17 #include <boost/enable_shared_from_this.hpp>
18 #include <pion/PionConfig.hpp>
19 #include <pion/net/HTTPWriter.hpp>
20 #include <pion/net/HTTPRequest.hpp>
31 public boost::enable_shared_from_this<HTTPRequestWriter>
47 static inline boost::shared_ptr<HTTPRequestWriter>
create(TCPConnectionPtr& tcp_conn,
50 return boost::shared_ptr<HTTPRequestWriter>(
new HTTPRequestWriter(tcp_conn, handler));
63 static inline boost::shared_ptr<HTTPRequestWriter>
create(TCPConnectionPtr& tcp_conn,
64 HTTPRequestPtr& http_request,
67 return boost::shared_ptr<HTTPRequestWriter>(
new HTTPRequestWriter(tcp_conn, http_request, handler));
86 setLogger(PION_GET_LOGGER(
"pion.net.HTTPRequestWriter"));
98 :
HTTPWriter(tcp_conn, handler), m_http_request(http_request)
100 setLogger(PION_GET_LOGGER(
"pion.net.HTTPRequestWriter"));
103 if (m_http_request->getContentLength() > 0
104 && m_http_request->getContent() != NULL
105 && m_http_request->getContent()[0] !=
'\0')
108 m_http_request->getContentLength());
121 m_http_request->prepareBuffersForSend(write_buffers,
129 boost::asio::placeholders::error,
130 boost::asio::placeholders::bytes_transferred);
139 virtual void handleWrite(
const boost::system::error_code& write_error,
140 std::size_t bytes_written)
146 PION_LOG_DEBUG(log_ptr,
"Sent HTTP request chunk of " << bytes_written <<
" bytes");
149 PION_LOG_DEBUG(log_ptr,
"Sent HTTP request of " << bytes_written <<
" bytes");
159 HTTPRequestPtr m_http_request;
162 std::string m_request_line;
167 typedef boost::shared_ptr<HTTPRequestWriter> HTTPRequestWriterPtr;
171 template <
typename T>
172 const HTTPRequestWriterPtr& operator<<(
const HTTPRequestWriterPtr& writer,
const T& data) {
HTTPRequestWriter(TCPConnectionPtr &tcp_conn, HTTPRequestPtr &http_request, FinishedHandler handler)
void finishedWriting(const boost::system::error_code &ec)
called after we have finished sending the HTTP message
virtual void prepareBuffersForSend(HTTPMessage::WriteBuffers &write_buffers)
bool sendingChunkedMessage() const
returns true if we are sending a chunked message to the client
HTTPRequest & getRequest(void)
returns a non-const reference to the request that will be sent
void writeNoCopy(const std::string &data)
virtual ~HTTPRequestWriter()
default destructor
void setLogger(PionLogger log_ptr)
sets the logger to be used
boost::function1< void, const boost::system::error_code & > FinishedHandler
function called after the HTTP message has been sent
std::vector< boost::asio::const_buffer > WriteBuffers
data type for I/O write buffers (these wrap existing data to be sent)
virtual WriteHandler bindToWriteHandler(void)
returns a function bound to HTTPWriter::handleWrite()
size_t getContentLength(void) const
returns the length of the payload content (in bytes)
boost::function2< void, const boost::system::error_code &, std::size_t > WriteHandler
data type for a function that handles write operations
PionLogger getLogger(void)
returns the logger currently in use
static boost::shared_ptr< HTTPRequestWriter > create(TCPConnectionPtr &tcp_conn, FinishedHandler handler=FinishedHandler())
virtual void handleWrite(const boost::system::error_code &write_error, std::size_t bytes_written)
HTTPRequestWriter(TCPConnectionPtr &tcp_conn, FinishedHandler handler)
static boost::shared_ptr< HTTPRequestWriter > create(TCPConnectionPtr &tcp_conn, HTTPRequestPtr &http_request, FinishedHandler handler=FinishedHandler())
void clear(void)
clears out all of the memory buffers used to cache payload content data
TCPConnectionPtr & getTCPConnection(void)
returns a shared pointer to the TCP connection