Commit 06f7988e authored by jan.koester's avatar jan.koester
Browse files

test

parent f6fb006d
Loading
Loading
Loading
Loading
+21 −1
Changes for src/http/HttpProxyServer.cpp: 21 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ std::string methodName(int requestType) {

HttpProxyController::HttpProxyController(std::vector<netplus::socket *> serverSockets,
                                          std::string listenerLabel,
                                          bool tlsActive,
                                          store::ConfigStore &configStore,
                                          auth::IAuthService &authService,
                                          plugin::PluginManager &pluginManager,
@@ -30,6 +31,7 @@ HttpProxyController::HttpProxyController(std::vector<netplus::socket *> serverSo
                                          tls::AcmeChallengeStore *acmeChallenges)
    : libhttppp::HttpEvent(std::move(serverSockets))
    , _listenerLabel(std::move(listenerLabel))
    , _tlsActive(tlsActive)
    , _configStore(configStore)
    , _authService(authService)
    , _pluginManager(pluginManager)
@@ -167,7 +169,7 @@ void HttpProxyController::RequestEvent(libhttppp::HttpRequest &curreq, const int
            ctx.origin = auth::AuthOrigin::HttpProxy;
            ctx.sourceIp = sourceIp;
            ctx.listener = _listenerLabel;
            ctx.tlsActive = false; // TODO: read from the accepting socket once mTLS/TLS-info plumbing exists
            ctx.tlsActive = _tlsActive;

            auto authResult = authenticate(curreq, ctx);
            if (!authResult.authenticated) {
@@ -238,6 +240,24 @@ void HttpProxyController::RequestEvent(libhttppp::HttpRequest &curreq, const int
            outreq.setHeaderData("host")->push_back(upstream.getHost());
            outreq.setHeaderData("connection")->push_back("close");

            // Standard reverse-proxy hints for the upstream: X-Forwarded-For chains (append to
            // whatever a prior proxy already put there, via the copy the loop above already
            // made); Host/Proto describe *this* hop only, so always set from what we actually
            // observed rather than trusting whatever value a client sent.
            std::string xff = sourceIp;
            if (auto *existingXff = outreq.getHeaderData("x-forwarded-for")) {
                if (auto *v = existingXff->getfirstValue()) {
                    xff = v->getvalue() + ", " + sourceIp;
                }
            }
            outreq.setHeaderData("x-forwarded-for")->push_back(xff);
            if (auto *hostHdr = curreq.getHeaderData("host")) {
                if (auto *v = hostHdr->getfirstValue()) {
                    outreq.setHeaderData("x-forwarded-host")->push_back(v->getvalue());
                }
            }
            outreq.setHeaderData("x-forwarded-proto")->push_back(_tlsActive ? "https" : "http");

            std::vector<char> body;
            if (method == "POST" || method == "PUT") {
                outreq.setRequestType(method == "POST" ? POSTREQUEST : PUTREQUEST);
+2 −0
Changes for src/http/HttpProxyServer.h: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ public:
    // listener on port 80 needs it.
    HttpProxyController(std::vector<netplus::socket *> serverSockets,
                         std::string listenerLabel,
                         bool tlsActive,
                         store::ConfigStore &configStore,
                         auth::IAuthService &authService,
                         plugin::PluginManager &pluginManager,
@@ -47,6 +48,7 @@ private:
    bool tryServeAcmeChallenge(libhttppp::HttpRequest &curreq, const std::string &url);

    std::string _listenerLabel;
    bool _tlsActive;
    store::ConfigStore &_configStore;
    auth::IAuthService &_authService;
    plugin::PluginManager &_pluginManager;