Skip to content

Commit 5d11bb3

Browse files
committed
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.
1 parent f5db252 commit 5d11bb3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Release/src/http/client/http_client_asio.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,9 +1229,17 @@ class asio_context : public request_context, public std::enable_shared_from_this
12291229
}
12301230
}
12311231

1232+
// Check for HEAD requests and status codes which cannot contain a
1233+
// message body in HTTP/1.1 (see 3.3.3/1 of the RFC 7230).
1234+
//
12321235
// note: need to check for 'chunked' here as well, azure storage sends both
12331236
// transfer-encoding:chunked and content-length:0 (although HTTP says not to)
1234-
if (m_request.method() == U("HEAD") || (!needChunked && m_content_length == 0))
1237+
const auto status = m_response.status_code();
1238+
if (m_request.method() == U("HEAD")
1239+
|| (status >= 100 && status < 200)
1240+
|| status == status_codes::NoContent
1241+
|| status == status_codes::NotModified
1242+
|| (!needChunked && m_content_length == 0))
12351243
{
12361244
// we can stop early - no body
12371245
const auto &progress = m_request._get_impl()->_progress_handler();

0 commit comments

Comments
 (0)