Repository navigation
Conversation
| destinationRequest.Version = HttpVersion.Version11; | ||
| destinationRequest.VersionPolicy = HttpVersionPolicy.RequestVersionOrLower; | ||
| destinationRequest.Method = HttpMethod.Get; | ||
| destinationRequest.Method = isH2WsRequest ? HttpMethod.Get : RequestUtilities.GetHttpMethod(context.Request.Method); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.