Skip to content

Commit 0a9a84c

Browse files
authored
Merge pull request microsoft#498 from vadz/fix-no-body-errors
Avoid spurious errors when handling HTTP responses without body
2 parents f5db252 + 5d11bb3 commit 0a9a84c

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)