runtime: HttpClient does not respect DefaultRequestVersion with version 3 and DefaultVersionPolicy.RequestVersionOrLower
Description
When you initialize a httpclient with the following configuration
Client = new HttpClient()
{
DefaultRequestVersion = HttpVersion.Version30,
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower
};
It will first attempt to make a h2 connection to the target server, if the server advertises h3 via alt-svc subsequent connections will be upgraded to http3.
Reproduction Steps
Initialize a httpclient with the following configuration
Client = new HttpClient()
{
DefaultRequestVersion = HttpVersion.Version30,
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower
};
Attempt to connect to a server that supports http3 running php Check the $_SERVER[‘SERVER_PROTOCOL’] and it will be “HTTP/2.0”
Expected behavior
HttpClient should first attempt to connect via quic/http3 as it is the DefaultRequestVersion, not HttpVersion.Version20
Actual behavior
HttpClient connects via h2 and checks for alt-svc to upgrade subsequent connections.
Regression?
No response
Known Workarounds
Use DefaultVersionPolicy.RequestVersionExact
Configuration
No response
Other information
My software operates in censorship prone environments. I’ve been testing the utilization of h3 to help improve connectivity in such environments. While the results have been positive, there does not seem to be a silver bullet that works for all users. I would think that given the provided configuration that a attempt would be made in h3, and if that fails then to try use h2/h1. Currently im shipping using DefaultVersionPolicy.RequestVersionExact but while this improves the connectivity of more users, I can predict some users local firewall or proxy configurations may make h3 requests impossible. In those cases I would like the httpclient to dropdown to standard tcp connections.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (17 by maintainers)
Probably just that H3 isn’t supported when using a proxy since we can’t tunnel UDP?
I can confirm with .net9, same situation fiddler classic running in the background, QuicConnection.IsSupported returns true, and the h3 connection attempt is met with a VersionNegotiationError with a null inner exception.
Added QuicError.ConnectionIdle, as that error is thrown + HttpRequestError = ConnectionError when UDP is blocked on 443
Thank you for the extra insight into the error codes
how does this filtering look?
How are we to decide which QUIC transport errors to be swallowed and which to be propagated? For comparison, if we fail to establish TCP connection we propagate that error to the user, we don’t attempt anything else.
You could provide them with an extension method, or a custom
HttpMessageHandlerthat does what you’re describing here. There are solutions/workarounds to this without your users doing the hard work and without changing .NET runtime itself.What I’m getting there is that your set up is pretty specific. In other words, this is not a common scenario. And for that reason, it’s also unlikely that we would do any changes. But I can keep this open to collect interest from other users to see if this gets any traction, we can then re-evaluate the current behavior.
I think this would be expected e.g. the client would not use the version unless there is confidence it can actually work. I you really want to force H/3 you can use
HttpVersionPolicy.RequestVersionExact