Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP 2.0 Support #71

Merged
merged 1 commit into from
Sep 2, 2024
Merged

HTTP 2.0 Support #71

merged 1 commit into from
Sep 2, 2024

Conversation

michel-pi
Copy link
Contributor

@michel-pi michel-pi commented Sep 2, 2024

This PR applies the HTTP Version to the HttpRequestMessage.
This is only available in .NET 8, since the HttpClient does not contain a Version before .NET 8.
You might extend configuration with a flag to tell whether to use 1.1 or 2.0 in this library, instead of using this PR.
Open for comments.

HttpRequestMessage.Version: "The default value is 1.1, unless you're targeting .NET Core 2.1 or 2.2. In that case, the default value is 2.0."
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage.version?view=netstandard-2.0#property-value

ArangoDB supports HTTP 2.0:
https://docs.arangodb.com/stable/develop/http-api/general-request-handling/

Meanwhile, we use this solution:

public class CustomHttpMessageHandler : DelegatingHandler
{
    public CustomHttpMessageHandler(HttpMessageHandler innerHandler)
        : base(innerHandler)
    {
    }

    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        request.Version = new Version(2, 0);
        request.VersionPolicy = HttpVersionPolicy.RequestVersionExact;

        HttpResponseMessage response = await base.SendAsync(request, cancellationToken);

        return response;
    }
}
var handler = new SocketsHttpHandler();

var customHttpHandler = new CustomHttpMessageHandler(handler);

HttpClient httpClient = new(customHttpHandler)
{
    DefaultRequestVersion = new Version(2, 0),
    DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact
};

ArangoConfiguration config = new()
{
    HttpClient = httpClient,
};

ArangoHttpTransport transport = new(config);

config.Transport = transport;

services.AddArango(arangoConfigSection.ConnectionString, config);

@coronabytes coronabytes merged commit 63bda43 into coronabytes:master Sep 2, 2024
1 check passed
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.

2 participants