Skip to content

Preserve HTTP methods when proxying upgrade requests - #3073

Open
MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:ws-preserveMethod
Open

MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:ws-preserveMethod

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

Fixes #3060 by preserving the incoming method when proxying HTTP/1.1 upgrade requests instead of rewriting them to GET.

Non-GET HTTP/1.1 WebSocket requests are forwarded as HTTP/1.1 upgrades, not converted to HTTP/2 Extended CONNECT. If the configured version policy disallows HTTP/1.1, request creation fails rather than sending the request with a different method. HTTP/2 WebSocket CONECT requests downgraded to HTTP/1.1 continue to use GET.

I debated whether to simply reject non-GET H1 WebSocket requests at the YARP layer instead of forwarding them with the original method, but I don't see a good argument either way, so I kept it for now.

@MihaZupan MihaZupan added this to the YARP 3.0 milestone Nov 18, 2026
@MihaZupan MihaZupan self-assigned this Nov 18, 2026
@MihaZupan
MihaZupan enabled auto-merge (squash) November 18, 2026 05:22
destinationRequest.Version = HttpVersion.Version11;
destinationRequest.VersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
destinationRequest.Method = HttpMethod.Get;
destinationRequest.Method = isH2WsRequest ? HttpMethod.Get : RequestUtilities.GetHttpMethod(context.Request.Method);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand this change. Before, we always changed to GET. Now we keep this logic for H2Ws but otherwise we are fine placing upgraded connections back to pool?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we get to this path, we've decided to proxy this request as an HTTP/1.1 Upgrade. The 99% case is that's because it's a WebSocket request.
HTTP/1.1 WebSocket traffic should always go over GET requests, but we weren't previously checking that and ended up just changing the method. This could in theory be problematic if you imposed harsher method restrictions on GET, and us changing the method would be a way to bypass those restrictions by just using a different method.
With this change if the incoming request is broken (using the wrong method), we'll just forward it as-is and let the backend decide what to do with that.

I'm not sure what you mean by "placing upgraded connections back to pool".
If the server does decide to upgrade a particular HTTP/1.1 request, that connection will never be pooled again since it can't be - the "upgrade" in this case means dropping HTTP and using the connection's transport as the pipe until it's closed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP/1.1 WebSocket path changes HTTP methods into GET

2 participants