diff options
author | Mauro Sardara <msardara@cisco.com> | 2020-02-14 10:38:36 +0100 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2020-02-14 10:38:36 +0100 |
commit | 663beb6a28ad4a2e8fc5cbe0f29d7970ab6bb418 (patch) | |
tree | 249fe9e45875e8aeb157e2f5ca64cd4032d2b805 | |
parent | df6894e4bed12525bd555d7e540bcfcf7e311b5e (diff) |
[HICN-520] Read correct number of bytes in HTTP proxy.
Change-Id: If22ad9db54bae0c1bde8f8bc0895c24e9ae23d65
Signed-off-by: Mauro Sardara <msardara@cisco.com>
-rw-r--r-- | apps/http-proxy/src/ATSConnector.cc | 32 | ||||
-rw-r--r-- | apps/http-proxy/src/ATSConnector.h | 2 |
2 files changed, 23 insertions, 11 deletions
diff --git a/apps/http-proxy/src/ATSConnector.cc b/apps/http-proxy/src/ATSConnector.cc index 600f1060f..f656a68cb 100644 --- a/apps/http-proxy/src/ATSConnector.cc +++ b/apps/http-proxy/src/ATSConnector.cc @@ -120,13 +120,27 @@ void ATSConnector::handleRead(std::error_code ec, std::size_t length, } } -void ATSConnector::doReadBody(std::size_t size) { - auto to_read = - size >= buffer_size ? (buffer_size - input_buffer_.size()) : size; - asio::async_read( - socket_, input_buffer_, asio::transfer_exactly(to_read), - std::bind(&ATSConnector::handleRead, this, std::placeholders::_1, - std::placeholders::_2, size)); +void ATSConnector::doReadBody(std::size_t body_size, + std::size_t additional_bytes) { + auto bytes_to_read = + body_size > additional_bytes ? (body_size - additional_bytes) : 0; + + auto to_read = bytes_to_read >= buffer_size + ? (buffer_size - input_buffer_.size()) + : bytes_to_read; + + if (to_read > 0) { + asio::async_read( + socket_, input_buffer_, asio::transfer_exactly(to_read), + std::bind(&ATSConnector::handleRead, this, std::placeholders::_1, + std::placeholders::_2, bytes_to_read)); + } else { + const uint8_t *buffer = + asio::buffer_cast<const uint8_t *>(input_buffer_.data()); + receive_callback_(buffer, body_size, !to_read, false); + input_buffer_.consume(body_size); + doReadHeader(); + } } void ATSConnector::doReadHeader() { @@ -139,13 +153,11 @@ void ATSConnector::doReadHeader() { std::size_t size = HTTPMessageFastParser::hasBody(buffer, length); auto additional_bytes = input_buffer_.size() - length; - auto bytes_to_read = - size >= additional_bytes ? (size - additional_bytes) : size; receive_callback_(buffer, length, !size, true); input_buffer_.consume(length); - doReadBody(bytes_to_read); + doReadBody(size, additional_bytes); } else { input_buffer_.consume(input_buffer_.size()); tryReconnection(); diff --git a/apps/http-proxy/src/ATSConnector.h b/apps/http-proxy/src/ATSConnector.h index aa5662e24..1ef2fa252 100644 --- a/apps/http-proxy/src/ATSConnector.h +++ b/apps/http-proxy/src/ATSConnector.h @@ -63,7 +63,7 @@ class ATSConnector { void doReadHeader(); - void doReadBody(std::size_t size); + void doReadBody(std::size_t body_size, std::size_t additional_bytes); void doWrite(); |