Fix bug in HttpClient
This commit is contained in:
parent
89764e864a
commit
278f7abae1
|
@ -19,11 +19,14 @@ int main()
|
|||
auto client=HttpAppFramework::instance().newHttpClient(netaddr.toIp(),80);
|
||||
auto req=HttpAppFramework::instance().newHttpRequest();
|
||||
req->setMethod(drogon::HttpRequest::kGet);
|
||||
int count=0;
|
||||
for(int i=0;i<10;i++)
|
||||
client->sendRequest(req,[](ReqResult result,const HttpResponse &response){
|
||||
client->sendRequest(req,[&](ReqResult result,const HttpResponse &response){
|
||||
std::cout<<"receive response!"<<std::endl;
|
||||
//auto headers=response.
|
||||
count++;
|
||||
std::cout<<response.getBody()<<std::endl;
|
||||
std::cout<<"count="<<count<<std::endl;
|
||||
});
|
||||
HttpAppFramework::instance().run();
|
||||
} else {
|
||||
|
|
|
@ -109,7 +109,7 @@ void HttpClientImpl::onRecvMessage(const trantor::TcpConnectionPtr &connPtr,tran
|
|||
auto cb=_reqAndCallbacks.front().second;
|
||||
cb(ReqResult::Ok,resp);
|
||||
_reqAndCallbacks.pop();
|
||||
|
||||
context->reset();
|
||||
LOG_TRACE<<"req buffer size="<<_reqAndCallbacks.size();
|
||||
if(!_reqAndCallbacks.empty())
|
||||
{
|
||||
|
@ -123,6 +123,6 @@ void HttpClientImpl::onRecvMessage(const trantor::TcpConnectionPtr &connPtr,tran
|
|||
_tcpClient.reset();
|
||||
}
|
||||
}
|
||||
context->reset();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,8 +86,11 @@ namespace drogon
|
|||
void reset()
|
||||
{
|
||||
state_ = kExpectRequestLine;
|
||||
res_state_ = HttpResponseParseState::kExpectResponseLine;
|
||||
HttpRequestImpl dummy;
|
||||
request_.swap(dummy);
|
||||
HttpResponseImpl dummy_res;
|
||||
response_.swap(dummy_res);
|
||||
}
|
||||
|
||||
void resetRes()
|
||||
|
|
|
@ -219,6 +219,19 @@ namespace drogon
|
|||
return _body;
|
||||
}
|
||||
|
||||
void swap(HttpResponseImpl &that)
|
||||
{
|
||||
_headers.swap(that._headers);
|
||||
_cookies.swap(that._cookies);
|
||||
std::swap(_statusCode,that._statusCode);
|
||||
std::swap(_v,that._v);
|
||||
_statusMessage.swap(that._statusMessage);
|
||||
std::swap(_closeConnection,that._closeConnection);
|
||||
_body.swap(that._body);
|
||||
std::swap(_left_body_length,that._left_body_length);
|
||||
std::swap(_current_chunk_length,that._current_chunk_length);
|
||||
std::swap(_contentType,that._contentType);
|
||||
}
|
||||
protected:
|
||||
static const std::string web_content_type_to_string(uint8_t contenttype);
|
||||
static const std::string web_response_code_to_string(int code);
|
||||
|
|
Loading…
Reference in New Issue