summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Papalini <micpapal@cisco.com>2020-02-14 10:00:46 +0000
committerGerrit Code Review <gerrit@fd.io>2020-02-14 10:00:46 +0000
commitc77f6b381fe29331c72f8abc6fdd4a4d3286f87b (patch)
tree6a7dac43153732350dbe5a51c72e74db0c266e80
parent591ad7f2ebcee826b7146a17cb319f4441445e5c (diff)
parent663beb6a28ad4a2e8fc5cbe0f29d7970ab6bb418 (diff)
Merge "[HICN-520] Read correct number of bytes in HTTP proxy."
-rw-r--r--apps/http-proxy/src/ATSConnector.cc32
-rw-r--r--apps/http-proxy/src/ATSConnector.h2
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 db485605f..dbec30353 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();