Skip to content

Commit

Permalink
Support 1xx non-final response
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Nov 3, 2016
1 parent a9a60ce commit 2df30b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/HttpConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ HttpRequestEntry::HttpRequestEntry(std::unique_ptr<HttpRequest> httpRequest)
{
}

void HttpRequestEntry::resetHttpHeaderProcessor()
{
proc_ = make_unique<HttpHeaderProcessor>(HttpHeaderProcessor::CLIENT_PARSER);
}

std::unique_ptr<HttpRequest> HttpRequestEntry::popHttpRequest()
{
return std::move(httpRequest_);
Expand Down Expand Up @@ -151,9 +156,16 @@ std::unique_ptr<HttpResponse> HttpConnection::receiveResponse()
socketRecvBuffer_->getBufferLength())) {
A2_LOG_INFO(
fmt(MSG_RECEIVE_RESPONSE, cuid_, proc->getHeaderString().c_str()));
auto result = proc->getResult();
if (result->getStatusCode() / 100 == 1) {
socketRecvBuffer_->drain(proc->getLastBytesProcessed());
outstandingHttpRequests_.front()->resetHttpHeaderProcessor();
return nullptr;
}

auto httpResponse = make_unique<HttpResponse>();
httpResponse->setCuid(cuid_);
httpResponse->setHttpHeader(proc->getResult());
httpResponse->setHttpHeader(std::move(result));
httpResponse->setHttpRequest(
outstandingHttpRequests_.front()->popHttpRequest());
socketRecvBuffer_->drain(proc->getLastBytesProcessed());
Expand Down
4 changes: 4 additions & 0 deletions src/HttpConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class HttpRequestEntry {
public:
HttpRequestEntry(std::unique_ptr<HttpRequest> httpRequest);

// Resets proc_ by recreating the object. Thus any object obtained
// by getHttpRequest() before this call is invalidated.
void resetHttpHeaderProcessor();

const std::unique_ptr<HttpRequest>& getHttpRequest() const
{
return httpRequest_;
Expand Down

0 comments on commit 2df30b1

Please sign in to comment.