1
This commit is contained in:
parent
7f4a8dcc27
commit
babcdc3792
@ -1,6 +1,7 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <a8/sysutils.h>
|
||||
#include <a8/mutable_xobject.h>
|
||||
|
||||
#include "httpproxy.h"
|
||||
#include "app.h"
|
||||
@ -42,19 +43,35 @@ std::string HttpProxy::HttpGet(a8::XParams param,
|
||||
request->on_error = on_error;
|
||||
request->url = url;
|
||||
request->url_params = url_params;
|
||||
if (request_hash_.find(request->req_id) != request_hash_.end()) {
|
||||
abort();
|
||||
}
|
||||
request_hash_[request->req_id] = request;
|
||||
|
||||
a8::MutableXObject* proxy_url_params = a8::MutableXObject::NewObject();
|
||||
proxy_url_params->SetVal("data", url_params.ToJsonStr());
|
||||
std::string proxy_url;
|
||||
JsonDataMgr::Instance()->GetHttpProxyUrl(proxy_url);
|
||||
f8::HttpClientPool::Instance()->HttpGet
|
||||
(a8::XParams()
|
||||
.SetSender(request),
|
||||
on_ok,
|
||||
on_error,
|
||||
[] (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);
|
||||
HttpProxy::Instance()->DestoryRequest(req);
|
||||
},
|
||||
proxy_url.c_str(),
|
||||
url_params,
|
||||
*proxy_url_params,
|
||||
rand() % MAX_SYS_HTTP_NUM
|
||||
);
|
||||
delete proxy_url_params;
|
||||
return request->req_id;
|
||||
}
|
||||
|
||||
@ -62,3 +79,9 @@ std::string HttpProxy::CreateRequestId()
|
||||
{
|
||||
return request_prefix_ + a8::XValue(App::Instance()->NewUuid()).GetString();
|
||||
}
|
||||
|
||||
void HttpProxy::DestoryRequest(HttpProxyRequest* request)
|
||||
{
|
||||
request_hash_.erase(request->req_id);
|
||||
delete request;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ class HttpProxy : public a8::Singleton<HttpProxy>
|
||||
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