diff --git a/client_http.hpp b/client_http.hpp index 025c274..ae0a215 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -749,6 +749,21 @@ namespace SimpleWeb { session->callback(ec); }); } + else if(2 + chunk_size > num_additional_bytes) { // If only end of chunk remains unread (\n or \r\n) + // Remove "\r\n" + if(2 + chunk_size - num_additional_bytes == 1) + istream.get(); + auto null_buffer = std::make_shared(2); + asio::async_read(*session->connection->socket, *null_buffer, asio::transfer_exactly(2 + chunk_size - num_additional_bytes), [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(!ec) + read_chunked_transfer_encoded(session, chunk_size_streambuf); + else + session->callback(ec); + }); + } else { // Remove "\r\n" istream.get(); diff --git a/server_http.hpp b/server_http.hpp index 3d78858..0536e92 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -650,7 +650,6 @@ namespace SimpleWeb { auto lock = session->connection->handler_runner->continue_lock(); if(!lock) return; - if(!ec) read_chunked_transfer_encoded(session, chunk_size_streambuf); else @@ -661,6 +660,21 @@ namespace SimpleWeb { this->on_error(session->request, ec); }); } + else if(2 + chunk_size > num_additional_bytes) { // If only end of chunk remains unread (\n or \r\n) + // Remove "\r\n" + if(2 + chunk_size - num_additional_bytes == 1) + istream.get(); + auto null_buffer = std::make_shared(2); + asio::async_read(*session->connection->socket, *null_buffer, asio::transfer_exactly(2 + chunk_size - num_additional_bytes), [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(!ec) + read_chunked_transfer_encoded(session, chunk_size_streambuf); + else + this->on_error(session->request, ec); + }); + } else { // Remove "\r\n" istream.get();