From 193e6bae2c0541ba6d73170fccd7c6e98692daef Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 31 Aug 2024 17:38:42 -0400 Subject: [PATCH 1/6] Add Version and HttpVersionPolicy support for HttpRequestMessage --- Refit/RefitSettings.cs | 7 +++++++ Refit/RequestBuilderImplementation.cs | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/Refit/RefitSettings.cs b/Refit/RefitSettings.cs index e7da59125..b439b731e 100644 --- a/Refit/RefitSettings.cs +++ b/Refit/RefitSettings.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Net; using System.Net.Http; using System.Reflection; using System.Runtime.Serialization; @@ -127,6 +128,12 @@ public Func< /// Optional Key-Value pairs, which are displayed in the property . /// public Dictionary? HttpRequestMessageOptions { get; set; } + +#if NET6_0_OR_GREATER + public Version Version { get; set; } = HttpVersion.Version11; + + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } = HttpVersionPolicy.RequestVersionOrLower; +#endif } /// diff --git a/Refit/RequestBuilderImplementation.cs b/Refit/RequestBuilderImplementation.cs index 59ef3affa..367fb84af 100644 --- a/Refit/RequestBuilderImplementation.cs +++ b/Refit/RequestBuilderImplementation.cs @@ -738,6 +738,8 @@ bool paramsContainsCancellationToken AddPropertiesToRequest(restMethod, ret, paramList); + AddVersionToRequest(ret); + // NB: The URI methods in .NET are dumb. Also, we do this // UriBuilder business so that we preserve any hardcoded query // parameters as well as add the parameterized ones. @@ -1032,6 +1034,14 @@ void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessag #endif } + static void AddVersionToRequest(HttpRequestMessage ret) + { +#if NET6_0_OR_GREATER + ret.Version = settings.Version; + ret.VersionPolicy = settings.VersionPolicy; +#endif + } + IEnumerable> ParseQueryParameter( object? param, ParameterInfo parameterInfo, From 9f72bc1fd391e2ed0e38e218d922dd993ca50431 Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 31 Aug 2024 17:51:12 -0400 Subject: [PATCH 2/6] Add one more #if NET6_0_OR_GREATER --- Refit/RequestBuilderImplementation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Refit/RequestBuilderImplementation.cs b/Refit/RequestBuilderImplementation.cs index 367fb84af..8b77ec2f3 100644 --- a/Refit/RequestBuilderImplementation.cs +++ b/Refit/RequestBuilderImplementation.cs @@ -737,9 +737,9 @@ bool paramsContainsCancellationToken AddHeadersToRequest(headersToAdd, ret); AddPropertiesToRequest(restMethod, ret, paramList); - +#if NET6_0_OR_GREATER AddVersionToRequest(ret); - +#endif // NB: The URI methods in .NET are dumb. Also, we do this // UriBuilder business so that we preserve any hardcoded query // parameters as well as add the parameterized ones. From 27fff6693bc3392aad8f6c9560f0d95f31e5c9a8 Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 7 Sep 2024 22:52:43 -0400 Subject: [PATCH 3/6] Fixes a build error because of VS automatic code --- Refit/RequestBuilderImplementation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit/RequestBuilderImplementation.cs b/Refit/RequestBuilderImplementation.cs index 8b77ec2f3..807cafb79 100644 --- a/Refit/RequestBuilderImplementation.cs +++ b/Refit/RequestBuilderImplementation.cs @@ -1034,7 +1034,7 @@ void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessag #endif } - static void AddVersionToRequest(HttpRequestMessage ret) + void AddVersionToRequest(HttpRequestMessage ret) { #if NET6_0_OR_GREATER ret.Version = settings.Version; From 44eceaa1e66b861644ee916eb5b6d058d797e603 Mon Sep 17 00:00:00 2001 From: Andy Date: Sun, 8 Sep 2024 14:39:39 -0400 Subject: [PATCH 4/6] Fixes test verification error --- Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt | 2 ++ Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt index faa5be175..b56eb7767 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt @@ -335,6 +335,8 @@ namespace Refit public System.Collections.Generic.Dictionary? HttpRequestMessageOptions { get; set; } public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; } public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; } + public Version Version { get; set; } + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } } public static class RequestBuilder { diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt index bf8a866b8..eb98cb407 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt @@ -335,6 +335,8 @@ namespace Refit public System.Collections.Generic.Dictionary? HttpRequestMessageOptions { get; set; } public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; } public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; } + public Version Version { get; set; } + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } } public static class RequestBuilder { From c48ee45dd745f8a944f316b6b0b9692d34b7465b Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 14 Sep 2024 21:38:46 -0400 Subject: [PATCH 5/6] Try the test again --- Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt | 4 ++-- Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt index b56eb7767..f3a590070 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt @@ -335,8 +335,8 @@ namespace Refit public System.Collections.Generic.Dictionary? HttpRequestMessageOptions { get; set; } public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; } public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; } - public Version Version { get; set; } - public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } + public Version Version { get; set; } = HttpVersion.Version11; + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } = HttpVersionPolicy.RequestVersionOrLower; } public static class RequestBuilder { diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt index eb98cb407..ef80231e5 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt @@ -335,8 +335,8 @@ namespace Refit public System.Collections.Generic.Dictionary? HttpRequestMessageOptions { get; set; } public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; } public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; } - public Version Version { get; set; } - public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } + public Version Version { get; set; } = HttpVersion.Version11; + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } = HttpVersionPolicy.RequestVersionOrLower; } public static class RequestBuilder { From ed29ccbeb11e3a3615d5961427878168149fc323 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Mon, 16 Sep 2024 00:50:10 +0100 Subject: [PATCH 6/6] Fix API Tests --- Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt | 4 ++-- Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt index f3a590070..e702291ea 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt @@ -335,8 +335,8 @@ namespace Refit public System.Collections.Generic.Dictionary? HttpRequestMessageOptions { get; set; } public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; } public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; } - public Version Version { get; set; } = HttpVersion.Version11; - public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } = HttpVersionPolicy.RequestVersionOrLower; + public System.Version Version { get; set; } + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } } public static class RequestBuilder { diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt index ef80231e5..4d9b1bc27 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt @@ -335,8 +335,8 @@ namespace Refit public System.Collections.Generic.Dictionary? HttpRequestMessageOptions { get; set; } public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; } public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; } - public Version Version { get; set; } = HttpVersion.Version11; - public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } = HttpVersionPolicy.RequestVersionOrLower; + public System.Version Version { get; set; } + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } } public static class RequestBuilder {