Loading src/http/HttpProxyServer.cpp +1 −0 Changes for src/http/HttpProxyServer.cpp: 1 added line, 0 removed lines. Original line number Diff line number Diff line #include "HttpProxyServer.h" #include "HttpProxyPath.h" #include "WebSocketProxy.h" #include <algorithm> #include <cctype> Loading src/http/WebSocketProxy.cpp +11 −5 Changes for src/http/WebSocketProxy.cpp: 11 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -216,7 +216,7 @@ bool isWebSocketUpgrade(libhttppp::HttpRequest &curreq) { return connectionHeaderRequestsUpgrade(connection) && toLower(upgrade) == "websocket"; } void handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, bool handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, const std::string &sourceIp, const std::string &upstreamBase, const std::string &forwardPath, Loading Loading @@ -283,15 +283,16 @@ void handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, std::vector<char> body(upstreamLeftover.begin(), upstreamLeftover.end()); curres.send(curreq, body, static_cast<int>(body.size())); upstreamSock->close(); return; return true; } auto clientSock = netplus::detachConnection(curreq); if (!clientSock) { // Backend doesn't support detaching (see connection.h), or the // connection is already gone -- nothing safe left to do. // connection is already gone -- nothing safe left to do. Not an // upstream health issue (it already answered with 101 above). upstreamSock->close(); return; return true; } std::vector<char> leftoverVec(curreq.RecvData.begin(), curreq.RecvData.end()); Loading @@ -303,7 +304,7 @@ void handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, << "), rejecting new upgrade" << std::endl; clientSock->close(); upstreamSock->close(); return; return true; } sendAll(*clientSock, headerPart); Loading @@ -311,13 +312,18 @@ void handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, std::thread(relayLoop, std::move(clientSock), std::move(upstreamSock), std::move(clientLeftover), std::move(upstreamLeftover), std::move(slot)) .detach(); return true; } catch (const std::exception &e) { // curreq's socket is still intact here -- detachConnection() is only // ever reached after a successful upstream response, so nothing // upstream of that point can have stolen it. std::cerr << "[ws] upgrade failed: " << e.what() << std::endl; libhttppp::HttpResponse curres; curres.setState(HTTP502); std::vector<char> body; curres.send(curreq, body, 0); return false; } } Loading Loading
src/http/HttpProxyServer.cpp +1 −0 Changes for src/http/HttpProxyServer.cpp: 1 added line, 0 removed lines. Original line number Diff line number Diff line #include "HttpProxyServer.h" #include "HttpProxyPath.h" #include "WebSocketProxy.h" #include <algorithm> #include <cctype> Loading
src/http/WebSocketProxy.cpp +11 −5 Changes for src/http/WebSocketProxy.cpp: 11 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -216,7 +216,7 @@ bool isWebSocketUpgrade(libhttppp::HttpRequest &curreq) { return connectionHeaderRequestsUpgrade(connection) && toLower(upgrade) == "websocket"; } void handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, bool handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, const std::string &sourceIp, const std::string &upstreamBase, const std::string &forwardPath, Loading Loading @@ -283,15 +283,16 @@ void handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, std::vector<char> body(upstreamLeftover.begin(), upstreamLeftover.end()); curres.send(curreq, body, static_cast<int>(body.size())); upstreamSock->close(); return; return true; } auto clientSock = netplus::detachConnection(curreq); if (!clientSock) { // Backend doesn't support detaching (see connection.h), or the // connection is already gone -- nothing safe left to do. // connection is already gone -- nothing safe left to do. Not an // upstream health issue (it already answered with 101 above). upstreamSock->close(); return; return true; } std::vector<char> leftoverVec(curreq.RecvData.begin(), curreq.RecvData.end()); Loading @@ -303,7 +304,7 @@ void handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, << "), rejecting new upgrade" << std::endl; clientSock->close(); upstreamSock->close(); return; return true; } sendAll(*clientSock, headerPart); Loading @@ -311,13 +312,18 @@ void handleWebSocketUpgrade(libhttppp::HttpRequest &curreq, std::thread(relayLoop, std::move(clientSock), std::move(upstreamSock), std::move(clientLeftover), std::move(upstreamLeftover), std::move(slot)) .detach(); return true; } catch (const std::exception &e) { // curreq's socket is still intact here -- detachConnection() is only // ever reached after a successful upstream response, so nothing // upstream of that point can have stolen it. std::cerr << "[ws] upgrade failed: " << e.what() << std::endl; libhttppp::HttpResponse curres; curres.setState(HTTP502); std::vector<char> body; curres.send(curreq, body, 0); return false; } } Loading