Skip to content

Commit

Permalink
Add default http request version and policy (#6641)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunghwan2789 authored Oct 31, 2023
1 parent e92bc8d commit 6a3893e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ private async Task<GraphQLHttpResponse> ExecuteInternalAsync(
// DO NOT move the writer out of this method.
using var arrayWriter = new ArrayWriter();
using var requestMessage = CreateRequestMessage(arrayWriter, request, requestUri);
#if NET5_0_OR_GREATER
requestMessage.Version = _http.DefaultRequestVersion;
requestMessage.VersionPolicy = _http.DefaultVersionPolicy;
#endif
var responseMessage = await _http.SendAsync(requestMessage, ResponseHeadersRead, ct).ConfigureAwait(false);
return new GraphQLHttpResponse(responseMessage);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Net;
using static HotChocolate.AspNetCore.Tests.Utilities.TestServerExtensions;

namespace HotChocolate.Transport.Http.Tests;

public class GraphQLHttpClientConfigurationTests
{
[Fact]
public async Task DefaultRequestVersion()
{
var httpClient = new HttpClient(new TestHttpMessageHandler(
request =>
{
Assert.Equal(HttpVersion.Version20, request.Version);
Assert.Equal(HttpVersionPolicy.RequestVersionOrHigher, request.VersionPolicy);
return new();
}
))
{
DefaultRequestVersion = HttpVersion.Version20,
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher,
};

var client = GraphQLHttpClient.Create(httpClient, true);
await client.SendAsync(new("{ __typename }", new(CreateUrl(default))), default);
}

class TestHttpMessageHandler(Func<HttpRequestMessage, HttpResponseMessage> sender) : HttpMessageHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return Task.FromResult(sender.Invoke(request));
}
}
}

0 comments on commit 6a3893e

Please sign in to comment.