This commit is contained in:
aozhiwei 2024-07-30 18:48:31 +08:00
parent cb97623222
commit 9cd4413b8c
2 changed files with 17 additions and 8 deletions

View File

@ -18,7 +18,7 @@ struct HttpProxyRequest
std::string req_id;
f8::HttpProxyCb cb;
std::string url;
a8::XObject url_params;
std::shared_ptr<a8::MutableXObject> url_params;
long long add_tick = 0;
};
@ -70,18 +70,18 @@ std::string HttpProxy::HttpGet(
if (f8::App::Instance()->Terminated()) {
return "";
}
AddSignParams(url, url_params, "");
std::shared_ptr<HttpProxyRequest> request = std::make_shared<HttpProxyRequest>();
request->req_id = CreateRequestId();
request->cb = cb;
request->url = url;
request->url_params = *url_params;
request->url_params = url_params;
request->add_tick = a8::XGetTickCount();
if (request_hash_.find(request->req_id) != request_hash_.end()) {
abort();
}
request_hash_[request->req_id] = request;
auto proxy_url_params = a8::MutableXObject::CreateObject();
proxy_url_params->SetVal("seq_id", request->req_id);
proxy_url_params->SetVal("target_url", std::string(url));
@ -104,7 +104,7 @@ std::string HttpProxy::HttpGet(
{
cost_time,
request->url,
request->url_params.ToJsonStr(),
request->url_params->ToJsonStr(),
});
#endif
} else {
@ -112,7 +112,7 @@ std::string HttpProxy::HttpGet(
{
cost_time,
request->url,
request->url_params.ToJsonStr(),
request->url_params->ToJsonStr(),
ctx->response
});
request->cb(false, rsp_obj, ctx);
@ -136,11 +136,12 @@ std::string HttpProxy::HttpPost(
if (f8::App::Instance()->Terminated()) {
return "";
}
AddSignParams(url, url_params, content);
std::shared_ptr<HttpProxyRequest> request = std::make_shared<HttpProxyRequest>();
request->req_id = CreateRequestId();
request->cb = cb;
request->url = url;
request->url_params = *url_params;
request->url_params = url_params;
request->add_tick = a8::XGetTickCount();
if (request_hash_.find(request->req_id) != request_hash_.end()) {
abort();
@ -172,7 +173,7 @@ std::string HttpProxy::HttpPost(
{
cost_time,
request->url,
request->url_params.ToJsonStr(),
request->url_params->ToJsonStr(),
});
#endif
} else {
@ -180,7 +181,7 @@ std::string HttpProxy::HttpPost(
{
cost_time,
request->url,
request->url_params.ToJsonStr(),
request->url_params->ToJsonStr(),
ctx->response
});
request->cb(false, rsp_obj, ctx);
@ -211,3 +212,9 @@ void HttpProxy::DestoryRequest(std::shared_ptr<HttpProxyRequest> request)
{
request_hash_.erase(request->req_id);
}
void HttpProxy::AddSignParams(const char* url,
std::shared_ptr<a8::MutableXObject> url_params, const std::string& post_data)
{
}

View File

@ -35,6 +35,8 @@ class HttpProxy : public a8::Singleton<HttpProxy>
private:
std::string CreateRequestId();
void AddSignParams(const char* url,
std::shared_ptr<a8::MutableXObject> url_params, const std::string& post_data);
private:
std::map<std::string, std::shared_ptr<HttpProxyRequest>> request_hash_;