Skip to content

Commit

Permalink
feat: remove propertiesToAdd (#1741)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison authored Jun 27, 2024
1 parent 44314ba commit f5b1690
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Refit/RequestBuilderImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RequestBuilderImplementation<TApi>(RefitSettings? refitSettings = null)
partial class RequestBuilderImplementation : IRequestBuilder
{
static readonly QueryAttribute DefaultQueryAttribute = new ();
static readonly Uri BaseUri = new Uri("http://api");
static readonly Uri BaseUri = new ("http://api");
readonly Dictionary<string, List<RestMethodInfoInternal>> interfaceHttpMethods;
readonly ConcurrentDictionary<
CloseGenericMethodKey,
Expand Down Expand Up @@ -641,7 +641,6 @@ bool paramsContainsCancellationToken
(basePath == "/" ? string.Empty : basePath) + restMethod.RelativePath;
var queryParamsToAdd = new List<KeyValuePair<string, string?>>();
var headersToAdd = new Dictionary<string, string?>(restMethod.Headers);
var propertiesToAdd = new Dictionary<string, object?>();

RestMethodParameterInfo? parameterInfo = null;

Expand Down Expand Up @@ -764,9 +763,8 @@ bool paramsContainsCancellationToken
}

//if property, add to populate into HttpRequestMessage.Properties
if (restMethod.PropertyParameterMap.TryGetValue(i, out var propertyParameter))
if (restMethod.PropertyParameterMap.ContainsKey(i))
{
propertiesToAdd[propertyParameter] = param;
isParameterMappedToRequest = true;
}

Expand Down Expand Up @@ -797,7 +795,7 @@ bool paramsContainsCancellationToken

AddHeadersToRequest(headersToAdd, ret);

AddPropertiesToRequest(restMethod, ret, propertiesToAdd);
AddPropertiesToRequest(restMethod, ret, paramList);

// NB: The URI methods in .NET are dumb. Also, we do this
// UriBuilder business so that we preserve any hardcoded query
Expand Down Expand Up @@ -980,8 +978,7 @@ static void AddHeadersToRequest(Dictionary<string, string?> headersToAdd, HttpRe
}
}

void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessage ret,
Dictionary<string, object?> propertiesToAdd)
void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessage ret, object[] paramList)
{
// Add RefitSetting.HttpRequestMessageOptions to the HttpRequestMessage
if (settings.HttpRequestMessageOptions != null)
Expand All @@ -996,16 +993,19 @@ void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessag
}
}

foreach (var property in propertiesToAdd)
for (var i = 0; i < paramList.Length; i++)
{
if (restMethod.PropertyParameterMap.TryGetValue(i, out var propertyKey))
{
#if NET6_0_OR_GREATER
ret.Options.Set(
new HttpRequestOptionsKey<object?>(property.Key),
property.Value
new HttpRequestOptionsKey<object?>(propertyKey),
paramList[i]
);
#else
ret.Properties[property.Key] = property.Value;
ret.Properties[propertyKey] = paramList[i];
#endif
}
}

// Always add the top-level type of the interface to the properties
Expand Down

0 comments on commit f5b1690

Please sign in to comment.