From b92ffb2625452c5b8f2bd673b2319bc590192818 Mon Sep 17 00:00:00 2001 From: Henry Castro Date: Wed, 22 Jun 2022 09:59:11 -0400 Subject: [PATCH] wsd: proxy: add a callback response handler common case, forward response to client or socket error. Change-Id: I7dc730e7cae7292b54ee8a6ac2a8b12a20c41fa4 Signed-off-by: Henry Castro --- wsd/ProxyRequestHandler.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wsd/ProxyRequestHandler.cpp b/wsd/ProxyRequestHandler.cpp index fef33702e..778980538 100644 --- a/wsd/ProxyRequestHandler.cpp +++ b/wsd/ProxyRequestHandler.cpp @@ -25,7 +25,29 @@ void ProxyRequestHandler::handleRequest(const std::string& relPath, uriProxy.getPort()); sessionProxy->setTimeout(std::chrono::seconds(10)); http::Request requestProxy(uriProxy.getPathAndQuery()); + http::Session::FinishedCallback proxyCallback = + [socket](const std::shared_ptr& httpSession) + { + try + { + std::shared_ptr httpResponse = httpSession->response(); + if (httpResponse->statusLine().statusCode() == 200) + { + socket->sendAndShutdown(*httpResponse); + } + else + { + HttpHelper::sendErrorAndShutdown(400, socket); + } + } + catch(...) + { + LOG_DBG("ProxyCallback: Unknown exception"); + HttpHelper::sendErrorAndShutdown(400, socket); + } + }; + sessionProxy->setFinishedHandler(proxyCallback); if (!sessionProxy->asyncRequest(requestProxy, *COOLWSD::getWebServerPoll())) { HttpHelper::sendErrorAndShutdown(400, socket);