handler: localize client to avoid queue stalls
This commit is contained in:
@@ -87,17 +87,6 @@ static std::string sha256(const std::string& string) {
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerHandler::init() {
|
|
||||||
m_client = new Pistache::Http::Experimental::Client();
|
|
||||||
m_client->init(Pistache::Http::Experimental::Client::options().threads(1).maxConnectionsPerHost(8));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CServerHandler::finish() {
|
|
||||||
m_client->shutdown();
|
|
||||||
delete m_client;
|
|
||||||
m_client = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CServerHandler::fingerprintForRequest(const Pistache::Http::Request& req) {
|
std::string CServerHandler::fingerprintForRequest(const Pistache::Http::Request& req) {
|
||||||
const auto HEADERS = req.headers();
|
const auto HEADERS = req.headers();
|
||||||
std::shared_ptr<const Pistache::Http::Header::AcceptEncoding> acceptEncodingHeader;
|
std::shared_ptr<const Pistache::Http::Header::AcceptEncoding> acceptEncodingHeader;
|
||||||
@@ -372,7 +361,10 @@ void CServerHandler::proxyPass(const Pistache::Http::Request& req, Pistache::Htt
|
|||||||
|
|
||||||
Debug::log(TRACE, "Method ({}): Forwarding to {}", (uint32_t)req.method(), FORWARD_ADDR + req.resource());
|
Debug::log(TRACE, "Method ({}): Forwarding to {}", (uint32_t)req.method(), FORWARD_ADDR + req.resource());
|
||||||
|
|
||||||
auto builder = m_client->prepareRequest(FORWARD_ADDR + req.resource(), req.method());
|
Pistache::Http::Experimental::Client client;
|
||||||
|
client.init(Pistache::Http::Experimental::Client::options().maxConnectionsPerHost(8).maxResponseSize(g_pConfig->m_config.max_request_size).threads(1));
|
||||||
|
|
||||||
|
auto builder = client.prepareRequest(FORWARD_ADDR + req.resource(), req.method());
|
||||||
builder.body(req.body());
|
builder.body(req.body());
|
||||||
for (auto it = req.cookies().begin(); it != req.cookies().end(); ++it) {
|
for (auto it = req.cookies().begin(); it != req.cookies().end(); ++it) {
|
||||||
builder.cookie(*it);
|
builder.cookie(*it);
|
||||||
@@ -432,4 +424,6 @@ void CServerHandler::proxyPass(const Pistache::Http::Request& req, Pistache::Htt
|
|||||||
});
|
});
|
||||||
Pistache::Async::Barrier<Pistache::Http::Response> b(resp);
|
Pistache::Async::Barrier<Pistache::Http::Response> b(resp);
|
||||||
b.wait_for(std::chrono::seconds(g_pConfig->m_config.proxy_timeout_sec));
|
b.wait_for(std::chrono::seconds(g_pConfig->m_config.proxy_timeout_sec));
|
||||||
|
|
||||||
|
client.shutdown();
|
||||||
}
|
}
|
||||||
@@ -11,9 +11,6 @@ class CServerHandler : public Pistache::Http::Handler {
|
|||||||
|
|
||||||
HTTP_PROTOTYPE(CServerHandler)
|
HTTP_PROTOTYPE(CServerHandler)
|
||||||
|
|
||||||
void init();
|
|
||||||
void finish();
|
|
||||||
|
|
||||||
void onRequest(const Pistache::Http::Request& req, Pistache::Http::ResponseWriter response);
|
void onRequest(const Pistache::Http::Request& req, Pistache::Http::ResponseWriter response);
|
||||||
|
|
||||||
void onTimeout(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter response);
|
void onTimeout(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter response);
|
||||||
@@ -36,6 +33,4 @@ class CServerHandler : public Pistache::Http::Handler {
|
|||||||
std::string token = "";
|
std::string token = "";
|
||||||
std::string error = "";
|
std::string error = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
Pistache::Http::Experimental::Client* m_client = nullptr;
|
|
||||||
};
|
};
|
||||||
@@ -86,7 +86,6 @@ int main(int argc, char** argv, char** envp) {
|
|||||||
opts.maxRequestSize(g_pConfig->m_config.max_request_size);
|
opts.maxRequestSize(g_pConfig->m_config.max_request_size);
|
||||||
endpoint->init(opts);
|
endpoint->init(opts);
|
||||||
auto handler = Pistache::Http::make_handler<CServerHandler>();
|
auto handler = Pistache::Http::make_handler<CServerHandler>();
|
||||||
handler->init();
|
|
||||||
endpoint->setHandler(handler);
|
endpoint->setHandler(handler);
|
||||||
|
|
||||||
endpoint->serveThreaded();
|
endpoint->serveThreaded();
|
||||||
@@ -115,7 +114,6 @@ int main(int argc, char** argv, char** envp) {
|
|||||||
|
|
||||||
Debug::log(LOG, "Shutting down, bye!");
|
Debug::log(LOG, "Shutting down, bye!");
|
||||||
|
|
||||||
handler->finish();
|
|
||||||
endpoint->shutdown();
|
endpoint->shutdown();
|
||||||
endpoint = nullptr;
|
endpoint = nullptr;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user