Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

SocketsHttpHandler: Add a switch to allow non-ascii headers#42978

Merged
Anipik merged 15 commits into
dotnet:release/3.1from
antonfirsov:af/http-allow-nonascii
Sep 17, 2020
Merged

SocketsHttpHandler: Add a switch to allow non-ascii headers#42978
Anipik merged 15 commits into
dotnet:release/3.1from
antonfirsov:af/http-allow-nonascii

Conversation

@antonfirsov

@antonfirsov antonfirsov commented Sep 7, 2020

Copy link
Copy Markdown

.NET Core's SocketHttpHandler does not allow sending non-ASCII characters in HTTP headers according to RFC, however in reality services accept/require other characters/encodings.

In dotnet/runtime#38711 we are introducing a generic solution for .NET 5. This is a 3.1-only workaround exposing two switches to relax header validation globally before the first usage of HttpClient, enabling advanced users to send Latin-1 encoded headers:

  • AppContext switch: System.Net.Http.SocketsHttpHandler.AllowLatin1Headers
  • Environment variable: DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_ALLOWLATIN1HEADERS

Customer Impact

Unblock migration to .NET Core 3.1 for customers who need to send Latin-1 headers.

Testing

The PR adds tests (and minimal necessary test infrastructure changes) based on the ones in dotnet/runtime#39468 and dotnet/runtime#39169 to make sure these scenarios do not regress.

Validation: we sent private builds to the partner asking for this feature, and they confirmed that the change fixes their issue.

Risk

Low. The workaround is hidden behind a switch, our default behavior remains unchanged.

@antonfirsov antonfirsov marked this pull request as draft September 8, 2020 11:06
@antonfirsov

antonfirsov commented Sep 8, 2020

Copy link
Copy Markdown
Author

I realized my current tests are far from being correct. Converting to draft until I fix them & address the review comment from Chris.

Done

@antonfirsov antonfirsov marked this pull request as ready for review September 8, 2020 15:35
@antonfirsov antonfirsov changed the title SocketsHttpHandler: Add a switch to allow non-ascii characters SocketsHttpHandler: Add a switch to allow non-ascii headers Sep 8, 2020
Comment thread src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/StaticHttpSettings.cs Outdated
@Tratcher Tratcher dismissed their stale review September 8, 2020 18:59

Addressed

@antonfirsov

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@antonfirsov

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

Comment thread src/Common/tests/System/Net/Http/Http2LoopbackConnection.cs Outdated
Comment thread src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/StaticHttpSettings.cs Outdated
Comment thread src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs Outdated
Comment thread src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs Outdated
Comment thread src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs Outdated
Comment thread src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HPack/HPackEncoder.cs Outdated
Comment thread src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/StaticHttpSettings.cs Outdated

@MihaZupan MihaZupan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM

Comment thread src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs Outdated
@karelz karelz added the Servicing-consider Issue for next servicing release review label Sep 11, 2020
@karelz karelz added this to the 3.1.x milestone Sep 11, 2020

@ManickaP ManickaP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@antonfirsov

Copy link
Copy Markdown
Author

No test failures are related to the change. (System.Text.RegularExpressions.Tests and System.Diagnostics.Tests.PerformanceDataTests do not use System.Net.Http)

@antonfirsov

Copy link
Copy Markdown
Author

@danmosemsft can you help pushing this forward for servicing approval?

@danmoseley

Copy link
Copy Markdown
Member

@antonfirsov usual procedure - create a port PR, @karelz supports it, let me know..

@danmoseley

Copy link
Copy Markdown
Member

Oops, this is the PR. Got used to seeing 3.1 in the title.

@danmoseley danmoseley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please double check that tests that set appcontext/set environment variables aren't affecting other tests in the same process.

@antonfirsov

Copy link
Copy Markdown
Author

All tests are isolated using RemoteExecutor. The test methods are invoked by derived classes. Couldn't define them in the base class because of RemoteExecutor limitations -- it's not able to invoke delegates defined in an abstract class, since it has no info about what to instantiate.

@danmoseley danmoseley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it - thanks

@leecow leecow added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 15, 2020
@leecow leecow modified the milestones: 3.1.x, 3.1.9 Sep 15, 2020
@karelz

karelz commented Sep 15, 2020

Copy link
Copy Markdown
Member

@danmosemsft now that it is approved -- can we merge it, or should we wait for someone to tell us to do that?

@danmoseley

Copy link
Copy Markdown
Member

You can go ahead and merge 5.0 PR's when marked servicing-approved plus the usual requirements - code reviewed and tests are good.

@antonfirsov

Copy link
Copy Markdown
Author

You can go ahead and merge 5.0 PR's

I hope this is also true for 3.1-only servicing PR-s :)

@ManickaP ManickaP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little nits, otherwise LGTM, thanks!

@danmoseley

Copy link
Copy Markdown
Member

I hope this is also true for 3.1-only servicing PR-s :)

Oops, my bad. For 3.1/2.1, we normally have @Anipik do the merge, as he knows when the branch is open. Let him know if this is ready to merge.

@Anipik Anipik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Packaging changes required here. We can merge this once the feedback is addressed the ci is green

@danmoseley

Copy link
Copy Markdown
Member

Ah yes that's the other reason it's good for @Anipik to merge the 2.1/3.1 changes -- because he helps check the packaging was done correctly - something we've gotten wrong more than once.

@antonfirsov

Copy link
Copy Markdown
Author

@Anipik this PR is ready to merge:
important feedback was addressed, changes got approval, failures are unrelated flaky tests (System.Text.RegularExpressions.Tests and System.Diagnostics.Tests.PerformanceDataTests do not use System.Net.Http).

@Anipik Anipik merged commit 6b06e7f into dotnet:release/3.1 Sep 17, 2020
antonfirsov pushed a commit to dotnet/docs that referenced this pull request Oct 30, 2020
Fixes 2 issues:
- HTTP/2 is enabled by default since 3.1, the docs did not reflect this change
- Document the AllowLatin1Headers switch introduced in dotnet/corefx#42978
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net.Http Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants