Skip to content

Commit 3eefa5a

Browse files
committed
Fixed Header add
1 parent 629a09a commit 3eefa5a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

SpotifyAPI/Web/IClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,31 @@ public interface IClient : IDisposable
1515
/// Downloads data from an URL and returns it
1616
/// </summary>
1717
/// <param name="url">An URL</param>
18+
/// <param name="headers"></param>
1819
/// <returns></returns>
1920
Tuple<ResponseInfo, string> Download(string url, Dictionary<string, string> headers = null);
2021

2122
/// <summary>
2223
/// Downloads data async from an URL and returns it
2324
/// </summary>
2425
/// <param name="url"></param>
26+
/// <param name="headers"></param>
2527
/// <returns></returns>
2628
Task<Tuple<ResponseInfo, string>> DownloadAsync(string url, Dictionary<string, string> headers = null);
2729

2830
/// <summary>
2931
/// Downloads data from an URL and returns it
3032
/// </summary>
3133
/// <param name="url">An URL</param>
34+
/// <param name="headers"></param>
3235
/// <returns></returns>
3336
Tuple<ResponseInfo, byte[]> DownloadRaw(string url, Dictionary<string, string> headers = null);
3437

3538
/// <summary>
3639
/// Downloads data async from an URL and returns it
3740
/// </summary>
3841
/// <param name="url"></param>
42+
/// <param name="headers"></param>
3943
/// <returns></returns>
4044
Task<Tuple<ResponseInfo, byte[]>> DownloadRawAsync(string url, Dictionary<string, string> headers = null);
4145

@@ -44,6 +48,7 @@ public interface IClient : IDisposable
4448
/// </summary>
4549
/// <typeparam name="T">The Type which the object gets converted to</typeparam>
4650
/// <param name="url">An URL</param>
51+
/// <param name="headers"></param>
4752
/// <returns></returns>
4853
Tuple<ResponseInfo, T> DownloadJson<T>(string url, Dictionary<string, string> headers = null);
4954

@@ -52,6 +57,7 @@ public interface IClient : IDisposable
5257
/// </summary>
5358
/// <typeparam name="T">The Type which the object gets converted to</typeparam>
5459
/// <param name="url">An URL</param>
60+
/// <param name="headers"></param>
5561
/// <returns></returns>
5662
Task<Tuple<ResponseInfo, T>> DownloadJsonAsync<T>(string url, Dictionary<string, string> headers = null);
5763

@@ -61,6 +67,7 @@ public interface IClient : IDisposable
6167
/// <param name="url">An URL</param>
6268
/// <param name="body">The Body-Data (most likely a JSON String)</param>
6369
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
70+
/// <param name="headers"></param>
6471
/// <returns></returns>
6572
Tuple<ResponseInfo, string> Upload(string url, string body, string method, Dictionary<string, string> headers = null);
6673

@@ -70,6 +77,7 @@ public interface IClient : IDisposable
7077
/// <param name="url">An URL</param>
7178
/// <param name="body">The Body-Data (most likely a JSON String)</param>
7279
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
80+
/// <param name="headers"></param>
7381
/// <returns></returns>
7482
Task<Tuple<ResponseInfo, string>> UploadAsync(string url, string body, string method, Dictionary<string, string> headers = null);
7583

@@ -79,6 +87,7 @@ public interface IClient : IDisposable
7987
/// <param name="url">An URL</param>
8088
/// <param name="body">The Body-Data (most likely a JSON String)</param>
8189
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
90+
/// <param name="headers"></param>
8291
/// <returns></returns>
8392
Tuple<ResponseInfo, byte[]> UploadRaw(string url, string body, string method, Dictionary<string, string> headers = null);
8493

@@ -88,6 +97,7 @@ public interface IClient : IDisposable
8897
/// <param name="url">An URL</param>
8998
/// <param name="body">The Body-Data (most likely a JSON String)</param>
9099
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
100+
/// <param name="headers"></param>
91101
/// <returns></returns>
92102
Task<Tuple<ResponseInfo, byte[]>> UploadRawAsync(string url, string body, string method, Dictionary<string, string> headers = null);
93103

@@ -98,6 +108,7 @@ public interface IClient : IDisposable
98108
/// <param name="url">An URL</param>
99109
/// <param name="body">The Body-Data (most likely a JSON String)</param>
100110
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
111+
/// <param name="headers"></param>
101112
/// <returns></returns>
102113
Tuple<ResponseInfo, T> UploadJson<T>(string url, string body, string method, Dictionary<string, string> headers = null);
103114

@@ -108,6 +119,7 @@ public interface IClient : IDisposable
108119
/// <param name="url">An URL</param>
109120
/// <param name="body">The Body-Data (most likely a JSON String)</param>
110121
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
122+
/// <param name="headers"></param>
111123
/// <returns></returns>
112124
Task<Tuple<ResponseInfo, T>> UploadJsonAsync<T>(string url, string body, string method, Dictionary<string, string> headers = null);
113125
}

SpotifyAPI/Web/SpotifyWebClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public Tuple<ResponseInfo, byte[]> DownloadRaw(string url, Dictionary<string, st
3838
{
3939
foreach (KeyValuePair<string, string> headerPair in headers)
4040
{
41-
client.DefaultRequestHeaders.Add(headerPair.Key, headerPair.Value);
41+
client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
4242
}
4343
}
4444
using (HttpResponseMessage response = Task.Run(() => client.GetAsync(url)).Result)
@@ -60,7 +60,7 @@ public async Task<Tuple<ResponseInfo, byte[]>> DownloadRawAsync(string url, Dict
6060
{
6161
foreach (KeyValuePair<string, string> headerPair in headers)
6262
{
63-
client.DefaultRequestHeaders.Add(headerPair.Key, headerPair.Value);
63+
client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
6464
}
6565
}
6666
using (HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false))
@@ -106,7 +106,7 @@ public Tuple<ResponseInfo, byte[]> UploadRaw(string url, string body, string met
106106
{
107107
foreach (KeyValuePair<string, string> headerPair in headers)
108108
{
109-
client.DefaultRequestHeaders.Add(headerPair.Key, headerPair.Value);
109+
client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
110110
}
111111
}
112112

@@ -133,7 +133,7 @@ public async Task<Tuple<ResponseInfo, byte[]>> UploadRawAsync(string url, string
133133
{
134134
foreach (KeyValuePair<string, string> headerPair in headers)
135135
{
136-
client.DefaultRequestHeaders.Add(headerPair.Key, headerPair.Value);
136+
client.DefaultRequestHeaders.TryAddWithoutValidation(headerPair.Key, headerPair.Value);
137137
}
138138
}
139139

0 commit comments

Comments
 (0)