1
This commit is contained in:
parent
0f27c9f860
commit
acffe3761b
@ -68,17 +68,16 @@ std::string HttpProxy::HttpGet(a8::XParams param,
|
||||
JsonDataMgr::Instance()->GetHttpProxyUrl(proxy_url);
|
||||
f8::HttpClientPool::Instance()->HttpGet
|
||||
(a8::XParams()
|
||||
.SetSender(request),
|
||||
.SetSender(request->req_id),
|
||||
[] (a8::XParams& param, a8::XObject& data)
|
||||
{
|
||||
HttpProxyRequest* req = (HttpProxyRequest*)(param.sender.GetUserData());
|
||||
req->on_ok(req->param, data);
|
||||
HttpProxy::Instance()->DestoryRequest(req);
|
||||
},
|
||||
[] (a8::XParams& param, const std::string& response)
|
||||
{
|
||||
HttpProxyRequest* req = (HttpProxyRequest*)(param.sender.GetUserData());
|
||||
req->on_error(req->param, response);
|
||||
HttpProxyRequest* req = HttpProxy::Instance()->GetRequest(param.sender.GetString());
|
||||
if (req) {
|
||||
req->on_error(req->param, response);
|
||||
}
|
||||
HttpProxy::Instance()->DestoryRequest(req);
|
||||
},
|
||||
proxy_url.c_str(),
|
||||
@ -94,6 +93,12 @@ std::string HttpProxy::CreateRequestId()
|
||||
return request_prefix_ + a8::XValue(App::Instance()->NewUuid()).GetString();
|
||||
}
|
||||
|
||||
HttpProxyRequest* HttpProxy::GetRequest(const std::string& req_id)
|
||||
{
|
||||
auto itr = request_hash_.find(req_id);
|
||||
return itr != request_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
void HttpProxy::DestoryRequest(HttpProxyRequest* request)
|
||||
{
|
||||
request_hash_.erase(request->req_id);
|
||||
|
@ -21,11 +21,12 @@ class HttpProxy : public a8::Singleton<HttpProxy>
|
||||
const char* url,
|
||||
a8::XObject url_params
|
||||
);
|
||||
HttpProxyRequest* GetRequest(const std::string& req_id);
|
||||
void DestoryRequest(HttpProxyRequest* request);
|
||||
|
||||
private:
|
||||
|
||||
std::string CreateRequestId();
|
||||
void DestoryRequest(HttpProxyRequest* request);
|
||||
|
||||
private:
|
||||
std::map<std::string, HttpProxyRequest*> request_hash_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user