Closed duranserkan closed 2 months ago
Even when configuring FlurlHttp Client's default DefaultVersionPolicy at program start...
Any idea why that doesn't work? Have you confirmed whether using HttpClient (without Flurl) and setting DefaultVersionPolicy
works as expected? If so, some else is going on - Flurl isn't using the underlying HttpClient that you think it is.
The issue arises because HttpRequestMessage sets a version policy when using its default constructor, and this policy always overrides the HttpClient defaults.
According to the .NET documentation, it states:
“This property has no effect on any of the Send or SendAsync overloads that accept a System.Net.Http.HttpRequestMessage.”
Based on this, it appears that the framework behaves as expected, as you correctly suspected. However, this creates a gray area for consumers of Flurl since we currently have no control over the HttpRequestMessage version policy directly.
To resolve this, I believe it would be reasonable for Flurl to check the HttpClient’s default version policy and apply it to HttpRequestMessage when appropriate. Additionally, I suggest enhancing FlurlHttpSettings by providing an option to explicitly set the HTTP version policy. If this option is configured, Flurl can then override the HttpClient’s version policy accordingly.
Ah, I get it now, thanks. I think you can accomplish this with BeforeCall
, which is a hook that can be used to manipulate the HttpRequestMessage
just before it's sent. This is available fluently request-by-request, or globally via the builder, which I suspect is the most useful in your case:
FlurlHttp.Clients.WithDefaults(builder =>
builder.BeforeCall(call => call.HttpRequestMessage.VersionPolicy = HttpVersionPolicy.RequestVersionExact));
Thank you for the guidance. Prenegotiated H2C works now with BeforeCall configuration.
Hello,
I am the author of the DRN-Project, which provides out-of-the-box solutions for enterprise application development. In this project, we use Flurl as the default HTTP client for its ease of use and testability, as shown in ExternalRequestTests.cs.
Context
I want to utilize prenegotiated H2C (HTTP/2 over TCP) without SSL to benefit from Linkerd's Automatic mTLS.
Meshed pods must be TLS’d by Linkerd, not by the application itself
Current Limitation
Currently, it is possible to set the HTTP version of the HttpRequestMessage using FlurlHttpSettings when the SendAsync method is called with IFlurlRequest, as shown in the source code here:
However, we cannot set the HttpRequestMessage.HttpVersionPolicy using FlurlHttpSettings. It currently defaults to HttpVersionPolicy.RequestVersionOrLower.
Need for Enhancement
As discussed by the .NET team:
Even when configuring FlurlHttp Client's default DefaultVersionPolicy at program start as shown below:
I still encounter the following error:
Error Log
Request
Can we add support to set HttpRequestMessage.HttpVersionPolicy using FlurlHttpSettings? It appears to be a straightforward addition, and I am willing to create a PR if this proposal is acceptable.
To be future-proof, a configuration action can also be set in FlurlHttpSettings for additional HttpRequestMessage configurations.
Thank you for your attention and consideration.