1
This commit is contained in:
parent
a2a217597e
commit
76f2d768cf
@ -15,6 +15,7 @@
|
|||||||
struct HttpProxyRequest
|
struct HttpProxyRequest
|
||||||
{
|
{
|
||||||
std::string req_id;
|
std::string req_id;
|
||||||
|
f8::HttpProxyCb cb;
|
||||||
std::string url;
|
std::string url;
|
||||||
a8::XObject url_params;
|
a8::XObject url_params;
|
||||||
long long add_tick = 0;
|
long long add_tick = 0;
|
||||||
@ -39,13 +40,9 @@ static void _ProxyCallback(f8::JsonHttpRequest* request)
|
|||||||
}
|
}
|
||||||
if (request->request.HasKey("errcode") &&
|
if (request->request.HasKey("errcode") &&
|
||||||
request->request.Get("errcode").GetInt() == 0) {
|
request->request.Get("errcode").GetInt() == 0) {
|
||||||
#if 0
|
req->cb(true, &request->request, nullptr);
|
||||||
req->on_ok(req->param, data);
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
#if 0
|
req->cb(false, &request->request, nullptr);
|
||||||
req->on_error(req->param, data.Get("errmsg").GetString());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
HttpProxy::Instance()->DestoryRequest(req);
|
HttpProxy::Instance()->DestoryRequest(req);
|
||||||
}
|
}
|
||||||
@ -70,10 +67,7 @@ std::string HttpProxy::HttpGet(
|
|||||||
{
|
{
|
||||||
std::shared_ptr<HttpProxyRequest> request = std::make_shared<HttpProxyRequest>();
|
std::shared_ptr<HttpProxyRequest> request = std::make_shared<HttpProxyRequest>();
|
||||||
request->req_id = CreateRequestId();
|
request->req_id = CreateRequestId();
|
||||||
#if 0
|
request->cb = cb;
|
||||||
request->param = param;
|
|
||||||
request->on_ok = on_ok;
|
|
||||||
request->on_error = on_error;
|
|
||||||
request->url = url;
|
request->url = url;
|
||||||
request->url_params = url_params;
|
request->url_params = url_params;
|
||||||
request->add_tick = a8::XGetTickCount();
|
request->add_tick = a8::XGetTickCount();
|
||||||
@ -95,44 +89,35 @@ std::string HttpProxy::HttpGet(
|
|||||||
std::string proxy_url;
|
std::string proxy_url;
|
||||||
JsonDataMgr::Instance()->GetHttpProxyUrl(proxy_url);
|
JsonDataMgr::Instance()->GetHttpProxyUrl(proxy_url);
|
||||||
f8::HttpClientPool::Instance()->HttpGet
|
f8::HttpClientPool::Instance()->HttpGet
|
||||||
(a8::XParams()
|
(
|
||||||
.SetSender(request->req_id),
|
[request] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||||
[] (a8::XParams& param, a8::XObject& data)
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(param.sender.GetString());
|
long long cost_time = a8::XGetTickCount() - request->add_tick;
|
||||||
if (req) {
|
if (ok) {
|
||||||
long long cost_time = a8::XGetTickCount() - req->add_tick;
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
f8::UdpLog::Instance()->Debug("ProxyHttpGet ok cost_time:%d url:%s params:%s",
|
f8::UdpLog::Instance()->Debug("ProxyHttpGet ok cost_time:%d url:%s params:%s",
|
||||||
{
|
{
|
||||||
cost_time,
|
cost_time,
|
||||||
req->url,
|
request->url,
|
||||||
req->url_params.ToJsonStr(),
|
request->url_params.ToJsonStr(),
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
} else {
|
||||||
},
|
|
||||||
[] (a8::XParams& param, const std::string& response)
|
|
||||||
{
|
|
||||||
std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(param.sender.GetString());
|
|
||||||
if (req) {
|
|
||||||
long long cost_time = a8::XGetTickCount() - req->add_tick;
|
|
||||||
f8::UdpLog::Instance()->Warning("ProxyHttpGet error cost_time:%d url:%s params:%s response:%s",
|
f8::UdpLog::Instance()->Warning("ProxyHttpGet error cost_time:%d url:%s params:%s response:%s",
|
||||||
{
|
{
|
||||||
cost_time,
|
cost_time,
|
||||||
req->url,
|
request->url,
|
||||||
req->url_params.ToJsonStr(),
|
request->url_params.ToJsonStr(),
|
||||||
response
|
ctx->response
|
||||||
});
|
});
|
||||||
req->on_error(req->param, response);
|
request->cb(false, rsp_obj, ctx);
|
||||||
|
HttpProxy::Instance()->DestoryRequest(request);
|
||||||
}
|
}
|
||||||
HttpProxy::Instance()->DestoryRequest(req);
|
|
||||||
},
|
},
|
||||||
proxy_url.c_str(),
|
proxy_url.c_str(),
|
||||||
*proxy_url_params,
|
*proxy_url_params,
|
||||||
rand() % MAX_SYS_HTTP_NUM
|
rand() % MAX_SYS_HTTP_NUM
|
||||||
);
|
);
|
||||||
#endif
|
|
||||||
return request->req_id;
|
return request->req_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
third_party/f8
vendored
2
third_party/f8
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 7f272dc6b3c72839997921cfa1a78a0118eb504c
|
Subproject commit 74dfc2b9f910f757d57cca73f35909061417fba1
|
Loading…
x
Reference in New Issue
Block a user