diff --git a/src/core/Handler.cpp b/src/core/Handler.cpp index 0f2f21a..01f8377 100644 --- a/src/core/Handler.cpp +++ b/src/core/Handler.cpp @@ -87,17 +87,6 @@ static std::string sha256(const std::string& string) { 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) { const auto HEADERS = req.headers(); std::shared_ptr 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()); - 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()); for (auto it = req.cookies().begin(); it != req.cookies().end(); ++it) { builder.cookie(*it); @@ -432,4 +424,6 @@ void CServerHandler::proxyPass(const Pistache::Http::Request& req, Pistache::Htt }); Pistache::Async::Barrier b(resp); b.wait_for(std::chrono::seconds(g_pConfig->m_config.proxy_timeout_sec)); + + client.shutdown(); } \ No newline at end of file diff --git a/src/core/Handler.hpp b/src/core/Handler.hpp index c5512f5..e779313 100644 --- a/src/core/Handler.hpp +++ b/src/core/Handler.hpp @@ -11,9 +11,6 @@ class CServerHandler : public Pistache::Http::Handler { HTTP_PROTOTYPE(CServerHandler) - void init(); - void finish(); - void onRequest(const Pistache::Http::Request& req, 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 error = ""; }; - - Pistache::Http::Experimental::Client* m_client = nullptr; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 56ae435..7397035 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,7 +86,6 @@ int main(int argc, char** argv, char** envp) { opts.maxRequestSize(g_pConfig->m_config.max_request_size); endpoint->init(opts); auto handler = Pistache::Http::make_handler(); - handler->init(); endpoint->setHandler(handler); endpoint->serveThreaded(); @@ -115,7 +114,6 @@ int main(int argc, char** argv, char** envp) { Debug::log(LOG, "Shutting down, bye!"); - handler->finish(); endpoint->shutdown(); endpoint = nullptr;