diff --git a/src/HotChocolate/AspNetCore/src/Transport.Http/DefaultGraphQLHttpClient.cs b/src/HotChocolate/AspNetCore/src/Transport.Http/DefaultGraphQLHttpClient.cs index ec629ef8ada..44202b00784 100644 --- a/src/HotChocolate/AspNetCore/src/Transport.Http/DefaultGraphQLHttpClient.cs +++ b/src/HotChocolate/AspNetCore/src/Transport.Http/DefaultGraphQLHttpClient.cs @@ -103,6 +103,10 @@ private async Task 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); } diff --git a/src/HotChocolate/AspNetCore/test/Transport.Http.Tests/GraphQLHttpClientConfigurationTests.cs b/src/HotChocolate/AspNetCore/test/Transport.Http.Tests/GraphQLHttpClientConfigurationTests.cs new file mode 100644 index 00000000000..a12cd23f40a --- /dev/null +++ b/src/HotChocolate/AspNetCore/test/Transport.Http.Tests/GraphQLHttpClientConfigurationTests.cs @@ -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 sender) : HttpMessageHandler + { + protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + return Task.FromResult(sender.Invoke(request)); + } + } +}