From 5d11bb375d51d4ea12c6878693eba1e71bba1d5e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 Jul 2017 17:34:00 +0200 Subject: [PATCH] Avoid spurious errors when handling HTTP responses without body There is no message body for 1xx, 203 and 304 HTTP responses (see section 3.3.3/1 of RFC 7230), yet we tried to read it nevertheless when using ASIO backend, resulting in "Failed to read response body" exception being thrown. Fix this by explicitly skipping reading the body for these status codes. --- Release/src/http/client/http_client_asio.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Release/src/http/client/http_client_asio.cpp b/Release/src/http/client/http_client_asio.cpp index 6a6786dcf5..2183c9c389 100644 --- a/Release/src/http/client/http_client_asio.cpp +++ b/Release/src/http/client/http_client_asio.cpp @@ -1229,9 +1229,17 @@ class asio_context : public request_context, public std::enable_shared_from_this } } + // Check for HEAD requests and status codes which cannot contain a + // message body in HTTP/1.1 (see 3.3.3/1 of the RFC 7230). + // // note: need to check for 'chunked' here as well, azure storage sends both // transfer-encoding:chunked and content-length:0 (although HTTP says not to) - if (m_request.method() == U("HEAD") || (!needChunked && m_content_length == 0)) + const auto status = m_response.status_code(); + if (m_request.method() == U("HEAD") + || (status >= 100 && status < 200) + || status == status_codes::NoContent + || status == status_codes::NotModified + || (!needChunked && m_content_length == 0)) { // we can stop early - no body const auto &progress = m_request._get_impl()->_progress_handler();