Commit 334ba8a8 authored by jan.koester's avatar jan.koester
Browse files

test

parent 0fff4c79
Loading
Loading
Loading
Loading
+17 −3
Changes for src/http/HttpProxyServer.cpp: 17 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
#include <cctype>
#include <iostream>
#include <set>
#include <stdexcept>

#include <netplus/socket.h>
#include <netplus/crypto/cert_verify.h>
@@ -146,7 +147,11 @@ void HttpProxyController::applyResponseCompression(libhttppp::HttpRequest &curre
    Encoding upstreamEnc = fromToken(upstreamEncoding);
    if (upstreamEnc == Encoding::Other) {
        // Some encoding we don't speak (deflate/zstd/a comma-joined list) -- leave body and
        // headers exactly as the upstream sent them rather than risk corrupting it.
        // headers exactly as the upstream sent them rather than risk corrupting it. content-
        // encoding is excluded from RequestEvent's generic header-copy loop (this function
        // owns it exclusively), so it must be restored here explicitly, or the still-encoded
        // body ships with no Content-Encoding header at all and every client mis-renders it.
        curres.setHeaderData("content-encoding")->push_back(upstreamEncoding);
        return;
    }

@@ -166,8 +171,17 @@ void HttpProxyController::applyResponseCompression(libhttppp::HttpRequest &curre
        bool decodedOk = (upstreamEnc == Encoding::Gzip) ? gzipDecompress(body, decoded)
                                                           : brotliDecompress(body, decoded);
        if (!decodedOk) {
            // Can't transcode or strip it -- forward exactly what the upstream sent
            // rather than deliver encoded bytes mislabeled as plain content.
            // Can't transcode it. upstreamEnc != wanted only means it wasn't negotiate()'s
            // *top* pick -- the client may still have explicitly declared it acceptable
            // (e.g. "Accept-Encoding: gzip;q=1.0, br;q=0.5" with a brotli upstream), in which
            // case forwarding as-is is safe. If the client never declared it acceptable at
            // all, forwarding it anyway guarantees every browser mis-renders a fully encoded
            // body as plain content -- fail the request instead of serving that.
            if (!accepts(acceptEncoding, upstreamEnc)) {
                throw std::runtime_error("upstream sent " + upstreamEncoding +
                                          "-encoded content the client never declared support "
                                          "for, and it could not be transcoded");
            }
            curres.setHeaderData("content-encoding")->push_back(upstreamEncoding);
            return;
        }