Fixes #298: corrected removal of chunk end when receiving larger chunks
This commit is contained in:
parent
d49072a4f1
commit
a20a729a40
3 changed files with 49 additions and 31 deletions
|
|
@ -543,7 +543,7 @@ namespace SimpleWeb {
|
|||
if(header_it != session->request->header.end()) {
|
||||
unsigned long long content_length = 0;
|
||||
try {
|
||||
content_length = stoull(header_it->second);
|
||||
content_length = std::stoull(header_it->second);
|
||||
}
|
||||
catch(const std::exception &) {
|
||||
if(this->on_error)
|
||||
|
|
@ -605,7 +605,7 @@ namespace SimpleWeb {
|
|||
bytes_transferred -= line.size() + 1;
|
||||
unsigned long chunk_size = 0;
|
||||
try {
|
||||
chunk_size = stoul(line, 0, 16);
|
||||
chunk_size = std::stoul(line, 0, 16);
|
||||
}
|
||||
catch(...) {
|
||||
if(this->on_error)
|
||||
|
|
@ -613,7 +613,12 @@ namespace SimpleWeb {
|
|||
return;
|
||||
}
|
||||
|
||||
if(2 + chunk_size + session->request->streambuf.size() > session->request->streambuf.max_size()) {
|
||||
if(chunk_size == 0) {
|
||||
this->find_resource(session);
|
||||
return;
|
||||
}
|
||||
|
||||
if(chunk_size + session->request->streambuf.size() > session->request->streambuf.max_size()) {
|
||||
auto response = std::shared_ptr<Response>(new Response(session, this->config.timeout_content));
|
||||
response->write(StatusCode::client_error_payload_too_large);
|
||||
if(this->on_error)
|
||||
|
|
@ -632,24 +637,25 @@ namespace SimpleWeb {
|
|||
source.consume(bytes_to_move);
|
||||
}
|
||||
|
||||
if((2 + chunk_size) > num_additional_bytes) {
|
||||
asio::async_read(*session->connection->socket, session->request->streambuf, asio::transfer_exactly(2 + chunk_size - num_additional_bytes), [this, session, chunk_size_streambuf, chunk_size](const error_code &ec, size_t /*bytes_transferred*/) {
|
||||
if(chunk_size > num_additional_bytes) {
|
||||
asio::async_read(*session->connection->socket, session->request->streambuf, asio::transfer_exactly(chunk_size - num_additional_bytes), [this, session, chunk_size_streambuf](const error_code &ec, size_t /*bytes_transferred*/) {
|
||||
auto lock = session->connection->handler_runner->continue_lock();
|
||||
if(!lock)
|
||||
return;
|
||||
|
||||
if(!ec) {
|
||||
std::istream istream(&session->request->streambuf);
|
||||
|
||||
// Remove "\r\n"
|
||||
istream.seekg(2, std::ios::end);
|
||||
istream.get();
|
||||
istream.get();
|
||||
auto null_buffer = std::make_shared<boost::asio::streambuf>(2);
|
||||
asio::async_read(*session->connection->socket, *null_buffer, asio::transfer_exactly(2), [this, session, chunk_size_streambuf, null_buffer](const error_code &ec, size_t /*bytes_transferred*/) {
|
||||
auto lock = session->connection->handler_runner->continue_lock();
|
||||
if(!lock)
|
||||
return;
|
||||
|
||||
if(chunk_size > 0)
|
||||
read_chunked_transfer_encoded(session, chunk_size_streambuf);
|
||||
else
|
||||
this->find_resource(session);
|
||||
if(!ec)
|
||||
read_chunked_transfer_encoded(session, chunk_size_streambuf);
|
||||
else
|
||||
this->on_error(session->request, ec);
|
||||
});
|
||||
}
|
||||
else if(this->on_error)
|
||||
this->on_error(session->request, ec);
|
||||
|
|
@ -660,10 +666,7 @@ namespace SimpleWeb {
|
|||
istream.get();
|
||||
istream.get();
|
||||
|
||||
if(chunk_size > 0)
|
||||
read_chunked_transfer_encoded(session, chunk_size_streambuf);
|
||||
else
|
||||
this->find_resource(session);
|
||||
read_chunked_transfer_encoded(session, chunk_size_streambuf);
|
||||
}
|
||||
}
|
||||
else if(this->on_error)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue