Skip to content

Commit

Permalink
Respect ResponseHeaderEncodingSelector for the Location header (dotne…
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan authored Dec 10, 2023
1 parent f0a6dbd commit 6de7549
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public string GetHeaderValue(ReadOnlySpan<byte> headerValue, Encoding? valueEnco
else if (knownHeader == KnownHeaders.Location)
{
// Normally Location should be in ISO-8859-1 but occasionally some servers respond with UTF-8.
if (TryDecodeUtf8(headerValue, out string? decoded))
// If the user set the ResponseHeaderEncodingSelector, we give that priority instead.
if (valueEncoding is null && TryDecodeUtf8(headerValue, out string? decoded))
{
return decoded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ private static readonly (string Name, Encoding ValueEncoding, string Separator,
("Cookie", Encoding.UTF8, "; ", new[] { "Cookies", "\uD83C\uDF6A", "everywhere" }),
("Set-Cookie", Encoding.UTF8, ", ", new[] { "\uD83C\uDDF8\uD83C\uDDEE" }),
("header-5", Encoding.UTF8, ", ", new[] { "\uD83D\uDE48\uD83D\uDE49\uD83D\uDE4A", "foo", "\uD83D\uDE03", "bar" }),
("bar", Encoding.UTF8, ", ", new[] { "foo" })
("bar", Encoding.UTF8, ", ", new[] { "foo" }),
("Location", Encoding.Latin1, ", ", new[] { "\u00D0\u00A4" })
};

[Fact]
Expand Down Expand Up @@ -538,7 +539,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(
foreach ((string name, Encoding valueEncoding, string separator, string[] values) in s_nonAsciiHeaders)
{
Assert.Contains(name, seenHeaderNames);
IEnumerable<string> receivedValues = Assert.Single(response.Headers, h => h.Key.Equals(name, StringComparison.OrdinalIgnoreCase)).Value;
IEnumerable<string> receivedValues = Assert.Single(response.Headers.NonValidated, h => h.Key.Equals(name, StringComparison.OrdinalIgnoreCase)).Value;
string value = Assert.Single(receivedValues);

string expected = valueEncoding.GetString(valueEncoding.GetBytes(string.Join(separator, values)));
Expand Down

0 comments on commit 6de7549

Please sign in to comment.