microsoft / reverse-proxy

A toolkit for developing high-performance HTTP reverse proxy applications.
https://microsoft.github.io/reverse-proxy
MIT License
8.55k stars 838 forks source link

HTTP3 GET requests get forwarded with Transfer-Encoding chunked #2644

Open nimatt opened 1 week ago

nimatt commented 1 week ago

Describe the bug

When performing a simple GET request over HTTP3 using Firefox, which gets forwarded using HTTP1.1. The outgoing request gets a StreamCopyHttpContent (with HTTP2 and HTTP1.1 it has null as content) which leads to Transfer-Encoding header being set to chunked. This makes one of our servers behind the proxy throw errors.

To Reproduce

Further technical details

Outgoing request GET / HTTP/1.1 Host: dev.local Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0 Accept-Encoding: gzip, deflate, br, zstd Accept-Language: en-US,en;q=0.5 Alt-Used: dev.local:8443 Cache-Control: no-cache Pragma: no-cache sec-fetch-dest: document sec-fetch-mode: navigate sec-fetch-site: none sec-fetch-user: ?1 priority: u=0, i X-Forwarded-For: 127.0.0.1 X-Forwarded-Host: dev.local X-Forwarded-Proto: https Transfer-Encoding: chunked

MihaZupan commented 5 days ago

That looks like a body detection bug in Kestrel, filed https://github.com/dotnet/aspnetcore/issues/58753.

You should be able to workaround the issue by overriding the IHttpRequestBodyDetectionFeature, e.g.

app.Use((context, next) =>
{
    if (HttpProtocol.IsHttp3(context.Request.Protocol) && HttpMethods.IsGet(context.Request.Method))
    {
        // Workaround https://github.com/microsoft/reverse-proxy/issues/2644
        context.Features.Set<IHttpRequestBodyDetectionFeature>(null);
    }

    return next();
});