Fix a error in the HttpClient class when a response has no content-length header (#698)
This commit is contained in:
parent
a060351f7a
commit
5426100bde
|
@ -79,8 +79,12 @@ void HttpClientImpl::createTcpClient()
|
|||
}
|
||||
auto resp = responseParser->responseImpl();
|
||||
responseParser->reset();
|
||||
thisPtr->handleResponse(resp, std::move(firstReq));
|
||||
thisPtr->tcpClientPtr_.reset();
|
||||
thisPtr->handleResponse(resp, std::move(firstReq), connPtr);
|
||||
if (!thisPtr->requestsBuffer_.empty())
|
||||
{
|
||||
thisPtr->createTcpClient();
|
||||
}
|
||||
return;
|
||||
}
|
||||
thisPtr->onError(ReqResult::NetworkFailure);
|
||||
}
|
||||
|
@ -236,6 +240,7 @@ void HttpClientImpl::sendRequest(const drogon::HttpRequestPtr &req,
|
|||
thisPtr->sendRequestInLoop(req, std::move(callback), timeout);
|
||||
});
|
||||
}
|
||||
|
||||
void HttpClientImpl::sendRequestInLoop(const HttpRequestPtr &req,
|
||||
HttpReqCallback &&callback,
|
||||
double timeout)
|
||||
|
@ -485,18 +490,30 @@ void HttpClientImpl::handleResponse(
|
|||
// pipeliningCallbacks_.size(); LOG_TRACE << "requests buffer size="
|
||||
// << requestsBuffer_.size();
|
||||
|
||||
if (!requestsBuffer_.empty())
|
||||
if (connPtr->connected())
|
||||
{
|
||||
auto &reqAndCallback = requestsBuffer_.front();
|
||||
sendReq(connPtr, reqAndCallback.first);
|
||||
pipeliningCallbacks_.push(std::move(reqAndCallback));
|
||||
requestsBuffer_.pop();
|
||||
if (!requestsBuffer_.empty())
|
||||
{
|
||||
auto &reqAndCallback = requestsBuffer_.front();
|
||||
sendReq(connPtr, reqAndCallback.first);
|
||||
pipeliningCallbacks_.push(std::move(reqAndCallback));
|
||||
requestsBuffer_.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (resp->ifCloseConnection() && pipeliningCallbacks_.empty())
|
||||
{
|
||||
tcpClientPtr_.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (resp->ifCloseConnection() && pipeliningCallbacks_.empty())
|
||||
while (!pipeliningCallbacks_.empty())
|
||||
{
|
||||
tcpClientPtr_.reset();
|
||||
auto cb = std::move(pipeliningCallbacks_.front());
|
||||
pipeliningCallbacks_.pop();
|
||||
cb.second(ReqResult::NetworkFailure, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -601,4 +618,4 @@ void HttpClientImpl::handleCookies(const HttpResponseImplPtr &resp)
|
|||
validCookies_.emplace_back(cookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ class HttpClientImpl : public HttpClient,
|
|||
void handleCookies(const HttpResponseImplPtr &resp);
|
||||
void handleResponse(const HttpResponseImplPtr &resp,
|
||||
std::pair<HttpRequestPtr, HttpReqCallback> &&reqAndCb,
|
||||
const trantor::TcpConnectionPtr &connPtr = nullptr);
|
||||
const trantor::TcpConnectionPtr &connPtr);
|
||||
void createTcpClient();
|
||||
std::queue<std::pair<HttpRequestPtr, HttpReqCallback>> pipeliningCallbacks_;
|
||||
std::queue<std::pair<HttpRequestPtr, HttpReqCallback>> requestsBuffer_;
|
||||
|
|
2
trantor
2
trantor
|
@ -1 +1 @@
|
|||
Subproject commit 26b2e53b671e90d6f5416d61cff4fe162171cd05
|
||||
Subproject commit b7c16286cdd4147e6ddf6b3831dc0578c794c10b
|
Loading…
Reference in New Issue