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)
|
if (headers != null)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
AddHeaders(headers);
|
||||||
{
|
|
||||||
_client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
using (HttpResponseMessage response = Task.Run(() => _client.GetAsync(url)).Result)
|
using (HttpResponseMessage response = Task.Run(() => _client.GetAsync(url)).Result)
|
||||||
{
|
{
|
||||||
@ -58,10 +55,7 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
if (headers != null)
|
if (headers != null)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
AddHeaders(headers);
|
||||||
{
|
|
||||||
_client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
using (HttpResponseMessage response = await _client.GetAsync(url).ConfigureAwait(false))
|
using (HttpResponseMessage response = await _client.GetAsync(url).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
@ -101,10 +95,7 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
if (headers != null)
|
if (headers != null)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
AddHeaders(headers);
|
||||||
{
|
|
||||||
_client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRequestMessage message = new HttpRequestMessage(new HttpMethod(method), url)
|
HttpRequestMessage message = new HttpRequestMessage(new HttpMethod(method), url)
|
||||||
@ -125,10 +116,7 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
if (headers != null)
|
if (headers != null)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
AddHeaders(headers);
|
||||||
{
|
|
||||||
_client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRequestMessage message = new HttpRequestMessage(new HttpMethod(method), url)
|
HttpRequestMessage message = new HttpRequestMessage(new HttpMethod(method), url)
|
||||||
@ -176,6 +164,18 @@ namespace SpotifyAPI.Web
|
|||||||
return newHeaders;
|
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)
|
private static HttpClientHandler CreateClientHandler(ProxyConfig proxyConfig = null)
|
||||||
{
|
{
|
||||||
HttpClientHandler clientHandler = new HttpClientHandler
|
HttpClientHandler clientHandler = new HttpClientHandler
|
||||||
|
Loading…
Reference in New Issue
Block a user