set output size on StockReplies properly

This commit is contained in:
Dennis Luxen 2014-03-24 18:13:40 +01:00
parent 482d79ef4b
commit 33faa2f252
3 changed files with 18 additions and 1 deletions

View File

@ -60,6 +60,8 @@ public:
std::vector<std::string> content; std::vector<std::string> content;
static Reply StockReply(status_type status); static Reply StockReply(status_type status);
void setSize(const unsigned size); void setSize(const unsigned size);
void SetUncompressedSize();
Reply(); Reply();
private: private:
static std::string ToString(Reply::status_type status); static std::string ToString(Reply::status_type status);

View File

@ -152,9 +152,11 @@ void Connection::handle_read(
); );
break; break;
case noCompression: case noCompression:
reply.SetUncompressedSize();
output_buffer = reply.toBuffers();
boost::asio::async_write( boost::asio::async_write(
TCP_socket, TCP_socket,
reply.toBuffers(), output_buffer,
strand.wrap( strand.wrap(
boost::bind( boost::bind(
&Connection::handle_write, &Connection::handle_write,
@ -167,6 +169,7 @@ void Connection::handle_read(
} }
} else if (!result) { } else if (!result) {
reply = Reply::StockReply(Reply::badRequest); reply = Reply::StockReply(Reply::badRequest);
boost::asio::async_write( boost::asio::async_write(
TCP_socket, TCP_socket,
reply.toBuffers(), reply.toBuffers(),

View File

@ -42,6 +42,18 @@ void Reply::setSize(const unsigned size) {
} }
} }
// Sets the size of the uncompressed output.
void Reply::SetUncompressedSize()
{
unsigned uncompressed_size = 0;
BOOST_FOREACH ( const std::string & current_line, content)
{
uncompressed_size += current_line.size();
}
setSize(uncompressed_size);
}
std::vector<boost::asio::const_buffer> Reply::toBuffers(){ std::vector<boost::asio::const_buffer> Reply::toBuffers(){
std::vector<boost::asio::const_buffer> buffers; std::vector<boost::asio::const_buffer> buffers;
buffers.push_back(ToBuffer(status)); buffers.push_back(ToBuffer(status));