mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 06:56:27 +00:00
Check if the header exists and replace it rather than add it again (#299)
This commit is contained in:
parent
f94fbc82f3
commit
9859e9d4ae
@ -39,10 +39,7 @@ namespace SpotifyAPI.Web
|
||||
{
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
||||
{
|
||||
_client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
|
||||
}
|
||||
AddHeaders(headers);
|
||||
}
|
||||
using (HttpResponseMessage response = Task.Run(() => _client.GetAsync(url)).Result)
|
||||
{
|
||||
@ -58,10 +55,7 @@ namespace SpotifyAPI.Web
|
||||
{
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
||||
{
|
||||
_client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
|
||||
}
|
||||
AddHeaders(headers);
|
||||
}
|
||||
using (HttpResponseMessage response = await _client.GetAsync(url).ConfigureAwait(false))
|
||||
{
|
||||
@ -101,10 +95,7 @@ namespace SpotifyAPI.Web
|
||||
{
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
||||
{
|
||||
_client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
|
||||
}
|
||||
AddHeaders(headers);
|
||||
}
|
||||
|
||||
HttpRequestMessage message = new HttpRequestMessage(new HttpMethod(method), url)
|
||||
@ -125,10 +116,7 @@ namespace SpotifyAPI.Web
|
||||
{
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
||||
{
|
||||
_client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
|
||||
}
|
||||
AddHeaders(headers);
|
||||
}
|
||||
|
||||
HttpRequestMessage message = new HttpRequestMessage(new HttpMethod(method), url)
|
||||
@ -176,6 +164,18 @@ namespace SpotifyAPI.Web
|
||||
return newHeaders;
|
||||
}
|
||||
|
||||
private void AddHeaders(Dictionary<string,string> headers)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
||||
{
|
||||
if (_client.DefaultRequestHeaders.Contains(headerPair.Key))
|
||||
{
|
||||
_client.DefaultRequestHeaders.Remove(headerPair.Key);
|
||||
}
|
||||
_client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private static HttpClientHandler CreateClientHandler(ProxyConfig proxyConfig = null)
|
||||
{
|
||||
HttpClientHandler clientHandler = new HttpClientHandler
|
||||
|
Loading…
Reference in New Issue
Block a user