Skip to content

Commit 35acaf0

Browse files
author
Meyn
committed
Fix WebHeaderCollection copying
1 parent a931892 commit 35acaf0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

DownloadAssistant/Options/WebRequestOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected WebRequestOptions(WebRequestOptions<TCompleated> options) : base(optio
4949
Timeout = options.Timeout;
5050
Headers = new();
5151
foreach (string key in options.Headers.AllKeys)
52-
Headers.Add(key, Headers[key]);
52+
Headers.Add(key, options.Headers[key]);
5353
UserAgent = options.UserAgent;
5454
}
5555
}

DownloadAssistant/Requests/WebRequest.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ namespace DownloadAssistant.Requests
3535
protected HttpRequestMessage GetPresetRequestMessage(HttpRequestMessage? httpRequest = null)
3636
{
3737
httpRequest ??= new HttpRequestMessage();
38-
foreach (string key in Options.Headers?.AllKeys ?? Array.Empty<string>())
39-
httpRequest.Headers.Add(key, Options.Headers?[key]);
38+
foreach (string key in Options.Headers.AllKeys ?? Array.Empty<string>())
39+
{
40+
string? headerValue = Options.Headers[key];
41+
if (!string.IsNullOrEmpty(headerValue))
42+
httpRequest.Headers.TryAddWithoutValidation(key, headerValue);
43+
}
4044

4145
if (!string.IsNullOrWhiteSpace(Options.UserAgent))
4246
httpRequest.Headers.Add("User-Agent", Options.UserAgent);

0 commit comments

Comments
 (0)