set output size on StockReplies properly
This commit is contained in:
parent
482d79ef4b
commit
33faa2f252
@ -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);
|
||||||
|
@ -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(),
|
||||||
|
@ -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));
|
||||||
|
Loading…
Reference in New Issue
Block a user