E5F1 Add Version and HttpVersionPolicy support for HttpRequestMessage by infofromca · Pull Request #1800 · reactiveui/refit · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ namespace Refit
public System.Collections.Generic.Dictionary<string, object>? HttpRequestMessageOptions { get; set; }
public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; }
public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; }
public System.Version Version { get; set; }
public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; }
}
public static class RequestBuilder
{
Expand Down
2 changes: 2 additions & 0 deletions Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ namespace Refit
public System.Collections.Generic.Dictionary<string, object>? HttpRequestMessageOptions { get; set; }
public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; }
public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; }
public System.Version Version { get; set; }
public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; }
}
public static class RequestBuilder
{
Expand Down
7 changes: 7 additions & 0 deletions Refit/RefitSettings.cs
D711
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,6 +128,12 @@ public Func<
/// Optional Key-Value pairs, which are displayed in the property <see cref="HttpRequestMessage.Properties"/>.
/// </summary>
public Dictionary<string, object>? 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
}

/// <summary>
Expand Down
12 changes: 11 additions & 1 deletion Refit/RequestBuilderImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +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.
Expand Down Expand Up @@ -1032,6 +1034,14 @@ void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessag
#endif
}

void AddVersionToRequest(HttpRequestMessage ret)
{
#if NET6_0_OR_GREATER
ret.Version = settings.Version;
ret.VersionPolicy = settings.VersionPolicy;
#endif
}

IEnumerable<KeyValuePair<string, string?>> ParseQueryParameter(
object? param,
ParameterInfo parameterInfo,
Expand Down
0