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

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

Merged
merged 15 commits into from Sep 17, 2020

Conversation

antonfirsov
Copy link
Member

@antonfirsov antonfirsov commented Sep 7, 2020

.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
Copy link
Member Author

antonfirsov commented Sep 8, 2020

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
@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.

Copy link
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

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

Change LGTM

@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
Copy link
Member

@ManickaP ManickaP left a comment

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
Member 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
Member Author

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

@danmoseley
Copy link
Member

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

@danmoseley
Copy link
Member

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

Copy link
Member

@danmoseley danmoseley left a comment

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
Member 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.

Copy link
Member

@danmoseley danmoseley left a comment

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
Copy link
Member

karelz commented Sep 15, 2020

@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
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
Member Author

You can go ahead and merge 5.0 PR's

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

Copy link
Member

@ManickaP ManickaP left a comment

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
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.

Copy link

@Anipik Anipik left a comment

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
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
Member 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 added 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
10 participants