Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.12.10
-
None
-
Ubuntu 20.04 and embedded Linux (buildroot compiled)
lighthhtpd server as frontend
Description
When a request comes through a forward-proxy (lighttpd mod_proxy), the request is handled and the correct route is called but the response never comes back to the client until the Server is closed or disconnectFromHost is called on the socket
example:
With a proxy redirecting all call behind a /API url on port 80 or 443 to the QhttpServer (on port 9000),
With a very simple server running on host 172.16.16.120 port 9000
QCoreApplication app(argc, argv); QHttpServer httpServer; httpServer.route("/proxyTest", [] () { return QJsonObject({{"success", true}});; }); httpServer.listen(QHostAddress::Any, 9000); return app.exec();
And the lighttpd proxy running on 172.16.16.115
#direct call bet@laptop:/home/bet$ curl "http://172.16.16.120:9000/proxyTest" {"success":true} #call through the proxy bet@laptop:/home/bet$ curl "http://172.16.16.115/API/proxyTest" ... #hang forever till the server application (QHttpServer) is closed {"success":true}
Modifying the sendResponse function to close the socket if it's a forward request make it works but it's not a good solution for websocket and the likes, the Forwarded header is not really a standard (lighttpd still use X-Forwarded-Host in my version (1.4.54)) and it doesn't solve the root cause of the problem
void QHttpServer::sendResponse(QHttpServerResponse &&response, const QHttpServerRequest &request, QTcpSocket *socket) { Q_D(QHttpServer); for (auto afterRequestHandler : d->afterRequestHandlers) response = std::move(afterRequestHandler(std::move(response), request)); response.write(makeResponder(request, socket)); if (request.headers().contains(QLatin1String("X-Forwarded-Host"))) socket->disconnectFromHost(); }
The parsed url is rather strange when the request has been forwarded (see forwarded_parsed_url.txt) but I don't think that it has any impact on the socket side.
I haven't found any cleaner way to get the responses so far.
Don't hesitate if I can provide anything else useful,
Bertrand