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;
static Reply StockReply(status_type status);
void setSize(const unsigned size);
void SetUncompressedSize();
Reply();
private:
static std::string ToString(Reply::status_type status);

View File

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