wsd: proxy: add a callback response handler
common case, forward response to client or socket error. Change-Id: I7dc730e7cae7292b54ee8a6ac2a8b12a20c41fa4 Signed-off-by: Henry Castro <hcastro@collabora.com>
This commit is contained in:
parent
92b2d9f6aa
commit
b92ffb2625
1 changed files with 22 additions and 0 deletions
|
@ -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<http::Session>& httpSession)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::shared_ptr<http::Response> 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);
|
||||
|
|
Loading…
Reference in a new issue