Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect ResponseHeaderEncodingSelector for the Location header #95810

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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]
@@ -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)));