204 http client support (#408)

* 204 http client support

* adding test for 204 response
This commit is contained in:
Victor Vazquez 2020-08-06 09:00:09 -07:00 committed by GitHub
parent 355184ef4f
commit a5c3f10b7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -19,13 +19,11 @@ std::unique_ptr<RawResponse> CurlTransport::Send(Context const& context, Request
{
switch (performing)
{
case CURLE_COULDNT_RESOLVE_HOST:
{
case CURLE_COULDNT_RESOLVE_HOST: {
throw Azure::Core::Http::CouldNotResolveHostException(
"Could not resolve host " + request.GetHost());
}
default:
{
default: {
throw Azure::Core::Http::TransportException(
"Error while sending request. " + std::string(curl_easy_strerror(performing)));
}
@ -377,7 +375,10 @@ void CurlSession::ReadStatusLineAndHeadersFromRawResponse()
// For Head request, set the length of body response to 0.
// Response will give us content-length as if we were not doing Head saying what would it be the
// length of the body. However, Server won't send body
if (this->m_request.GetMethod() == HttpMethod::Head)
// For NoContent status code, also need to set conentLength to 0.
// https://github.com/Azure/azure-sdk-for-cpp/issues/406
if (this->m_request.GetMethod() == HttpMethod::Head
|| this->m_response->GetStatusCode() == Azure::Core::Http::HttpStatusCode::NoContent)
{
this->m_contentLength = 0;
this->m_bodyStartInBuffer = -1;

View File

@ -42,6 +42,17 @@ namespace Azure { namespace Core { namespace Test {
CheckBodyFromBuffer(*response, expectedResponseBodySize + 6 + 13);
}
TEST_F(TransportAdapter, get204)
{
std::string host("http://mt3.google.com/generate_204");
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host);
auto response = pipeline.Send(context, request);
checkResponseCode(response->GetStatusCode(), Azure::Core::Http::HttpStatusCode::NoContent);
auto expectedResponseBodySize = std::stoull(response->GetHeaders().at("content-length"));
CheckBodyFromBuffer(*response, expectedResponseBodySize);
}
TEST_F(TransportAdapter, getLoop)
{
std::string host("http://httpbin.org/get");