This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
SocketsHttpHandler: Add a switch to allow non-ascii headers #42978
Merged
Anipik
merged 15 commits into
dotnet:release/3.1
from
antonfirsov:af/http-allow-nonascii
Sep 17, 2020
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f98796a
Implement AllowNonAsciiHeaders option + tests
antonfirsov 4753b19
add comments
antonfirsov 16278ad
Move AllowNonAsciiHeaders to new class to fix build
antonfirsov 4a6d304
fix tests + cover non- ISO-8859 cases
antonfirsov 9821bfe
validate for 0xFF when AllowNonAsciiHeaders is true
antonfirsov bb2424f
MultipartContentTest.ReadAsStreamAsync_CanEncodeLatin1
antonfirsov dd9efa5
remove commented lines
antonfirsov 43f534b
rename switches
antonfirsov db83595
fix Http2 tests
antonfirsov c4793d0
naming
antonfirsov 84ae85a
try fixing CI builds
antonfirsov fee785d
address review findings
antonfirsov aae055d
remove Lazy<bool>
antonfirsov 48bccd0
add shared Latin1Encoding field to HttpHeaderData
antonfirsov e8397af
changed foreach loop for consistency
antonfirsov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/StaticHttpSettings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace System.Net.Http | ||
| { | ||
| internal static class StaticHttpSettings | ||
|
antonfirsov marked this conversation as resolved.
|
||
| { | ||
| private const string AllowLatin1CharactersEnvironmentVariableSettingName = "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_ALLOWLATIN1HEADERS"; | ||
| private const string AllowLatin1CharactersAppCtxSettingName = "System.Net.Http.SocketsHttpHandler.AllowLatin1Headers"; | ||
|
|
||
| // Disables a validation that checks whether Http headers contain a non-ASCII character. | ||
| // This is a workaround that has been introduced as a patch specific to the 3.1 branch. | ||
| // Unlike options in HttpConnectionSettings, this one has a global scope. | ||
| // Lazy initialization is being used to make sure clients can also use AppContext.SetSwitch() or Environment.SetEnvironmentVariable() | ||
| // before the first calls to HttpClient API-s. | ||
| internal static bool AllowLatin1Headers { get; } = GetAllowLatin1HeadersSetting(); | ||
|
|
||
| internal static int EncodingValidationMask => AllowLatin1Headers ? 0xFF00 : 0xFF80; | ||
|
|
||
| private static bool GetAllowLatin1HeadersSetting() | ||
| { | ||
| // First check for the AppContext switch, giving it priority over the environment variable. | ||
| if (AppContext.TryGetSwitch(AllowLatin1CharactersAppCtxSettingName, out bool value)) | ||
| { | ||
| return value; | ||
| } | ||
|
|
||
| // AppContext switch wasn't used. Check the environment variable. | ||
| string envVar = Environment.GetEnvironmentVariable(AllowLatin1CharactersEnvironmentVariableSettingName); | ||
| if (envVar != null && (envVar.Equals("true", StringComparison.OrdinalIgnoreCase) || envVar.Equals("1"))) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.