Skip to content

Commit

Permalink
Add initial (non-functioning) keepalive support in S3Client
Browse files Browse the repository at this point in the history
(cherry picked from commit 3c62a5b)
  • Loading branch information
qris committed Jun 1, 2017
1 parent ac52f32 commit 0bcc722
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions lib/httpserver/S3Client.cpp
Expand Up @@ -178,7 +178,8 @@ HTTPResponse S3Client::FinishAndSendRequest(HTTPRequest::Method Method,
}

request.AddHeader("Authorization", auth_code);

HTTPResponse response;

if (mpSimulator)
{
if (pStreamToSend)
Expand All @@ -187,11 +188,13 @@ HTTPResponse S3Client::FinishAndSendRequest(HTTPRequest::Method Method,
}

request.SetForReading();
CollectInBufferStream response_buffer;
HTTPResponse response(&response_buffer);

mpSimulator->Handle(request, response);
return response;

// TODO FIXME: HTTPServer::Connection does some post-processing on every
// response to determine whether Connection: keep-alive is possible.
// We should do that here too, but currently our HTTP implementation
// doesn't support chunked encoding, so it's disabled there, so we don't
// do it here either.
}
else
{
Expand All @@ -203,7 +206,7 @@ HTTPResponse S3Client::FinishAndSendRequest(HTTPRequest::Method Method,
mapClientSocket->Open(Socket::TypeINET,
mHostName, mPort);
}
return SendRequest(request, pStreamToSend,
response = SendRequest(request, pStreamToSend,
pStreamContentType);
}
catch (ConnectionException &ce)
Expand All @@ -214,7 +217,7 @@ HTTPResponse S3Client::FinishAndSendRequest(HTTPRequest::Method Method,
// try to reconnect, just once
mapClientSocket->Open(Socket::TypeINET,
mHostName, mPort);
return SendRequest(request, pStreamToSend,
response = SendRequest(request, pStreamToSend,
pStreamContentType);
}
else
Expand All @@ -224,6 +227,17 @@ HTTPResponse S3Client::FinishAndSendRequest(HTTPRequest::Method Method,
}
}
}

// It's not valid to have a keep-alive response if the length isn't known.
// S3Simulator should really check this, but depending on how it's called above,
// it might be possible to bypass that check, so this is a double-check.
ASSERT(response.GetContentLength() >= 0 || !response.IsKeepAlive());

BOX_TRACE("S3Client: " << mHostName << " < " << response.GetResponseCode() <<
": " << response.GetContentLength() << " bytes")
response.SetForReading();

return response;
}

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -254,6 +268,8 @@ HTTPResponse S3Client::SendRequest(HTTPRequest& rRequest,
}
else
{
// No stream, so it's always safe to enable keep-alive
rRequest.SetClientKeepAliveRequested(true);
rRequest.Send(*mapClientSocket, mNetworkTimeout);
response.Receive(*mapClientSocket, mNetworkTimeout);
}
Expand Down

0 comments on commit 0bcc722

Please sign in to comment.