From a3e93fad6214fcf106d193277dd57a26a91fd1ff Mon Sep 17 00:00:00 2001 From: Mark Blakeney Date: Wed, 3 Jun 2026 08:58:19 +1000 Subject: [PATCH] Fix Host header forwarding to support reverse proxy usage Remove the Host header from forwarded requests so that aiohttp automatically sets the correct Host header based on the target URL. Previously, when corsproxy was used behind a reverse proxy (like Traefik), it would forward the client's Host header (e.g., proxy.example.com) to the target server. Many target servers using virtual host configurations would respond with 404 errors because they didn't recognize the proxy's hostname. Now, by filtering out the Host header before forwarding, aiohttp sets the correct Host header based on the target URL (e.g., www.researchcatalogue.net), ensuring the target server receives the expected hostname. This change maintains backward compatibility while fixing the issue for users behind reverse proxies without requiring manual Host header configuration in the reverse proxy. Fixes #9 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- corsproxy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/corsproxy b/corsproxy index 11541bc..e74b4e4 100755 --- a/corsproxy +++ b/corsproxy @@ -64,7 +64,10 @@ async def get(request: Request) -> Response: url = urlunsplit(urlsplit(str(request.url))._replace(scheme='', netloc='')) method = request.method - hdr = request.headers + # Create mutable copy of headers and remove Host header so aiohttp + # sets it correctly based on the target URL instead of forwarding + # the client's Host header + hdr = {k: v for k, v in request.headers.items() if k.lower() != 'host'} if method == 'GET': func = session.get(url, headers=hdr)