204 http client support (#408)
* 204 http client support * adding test for 204 response
This commit is contained in:
parent
355184ef4f
commit
a5c3f10b7d
@ -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;
|
||||
|
||||
@ -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");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user