Skip to content

Allow trimming out HTTP3 support #117012

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

Merged
merged 4 commits into from
Jul 2, 2025

Conversation

MichalStrehovsky
Copy link
Member

Fixes #77420.

This is a meaningful saving to leave on the table. For following app:

Console.WriteLine(new HttpClient().GetStringAsync("https://bing.com").Result);

PublishAot without this switch: 4.91 MB
PublishAot with this switch: 4.14 MB

We might even go as far as disabling HTTP3 on native AOT by default since #73290 reached the dreaded Future milestone and as far as I understand HTTP3 doesn't actually work without extra gestures anyway.

Fixes dotnet#77420.

This is a meaningful saving to leave on the table. For following app:

```csharp
Console.WriteLine(new HttpClient().GetStringAsync("https://bing.com").Result);
```

PublishAot without this switch: 4.91 MB
PublishAot with this switch: 4.14 MB

We might even go as far as disabling HTTP3 on native AOT by default since dotnet#73290 reached the dreaded Future milestone.
@Copilot Copilot AI review requested due to automatic review settings June 25, 2025 06:13
@MichalStrehovsky MichalStrehovsky added area-System.Net.Http linkable-framework Issues associated with delivering a linker friendly framework labels Jun 25, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces an AppContext switch to allow trimming out HTTP/3 support and reduces native AOT footprint by disabling all HTTP/3 code paths when the switch is off.

  • Adds a new GlobalHttpSettings.SocketsHttpHandler.AllowHttp3 feature switch
  • Updates HttpConnectionPool to guard HTTP/3 code on the new switch
  • Introduces a trimming test (QuicTrimmedTest.cs) and project entry to verify removal of System.Net.Quic

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/libraries/System.Net.Http/tests/TrimmingTests/System.Net.Http.TrimmingTests.proj Registers QuicTrimmedTest.cs with the Http3Support switch disabled
src/libraries/System.Net.Http/tests/TrimmingTests/QuicTrimmedTest.cs Implements a console test that ensures the Quic assembly is removed when HTTP/3 is trimmed
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.cs Surrounds all HTTP/3 usage with AllowHttp3 checks
src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs Defines the System.Net.SocketsHttpHandler.Http3Support feature switch and AllowHttp3 property
Comments suppressed due to low confidence (2)

src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs:43

  • Add an XML documentation comment above the AllowHttp3 property to explain its purpose, default behavior, and how to override it at runtime or via AppContext.
            [FeatureSwitchDefinition("System.Net.SocketsHttpHandler.Http3Support")]

src/libraries/System.Net.Http/tests/TrimmingTests/System.Net.Http.TrimmingTests.proj:12

  • Consider adding a runtime functional test to verify that setting AllowHttp3 to false actually prevents HTTP/3 connections in HttpClient, not just trimming the assembly.
    <TestConsoleAppSourceFiles Include="QuicTrimmedTest.cs">

@vitek-karas
Copy link
Member

/fyi @simonrozsival

@MichalStrehovsky
Copy link
Member Author

One thing I obviously struggled with is why we have both IsHttp3Supported and AllowHttp3, so now some places need to check both to get actual dead code elimination (IsHttp3Supported is not deadcoded outside the select few platforms I assume).

Maybe there should be just one place to control this, but I didn't want to regress mobile platforms and I'm not sure if it is actually allowed to enable HTTP3 on mobile platforms (feature switches can be overriden; what is in IsHttp3Supported is currently hardcoded and cannot be changed at publish/runtime).

@stephentoub
Copy link
Member

cc: @karelz

@MichalStrehovsky
Copy link
Member Author

dotnet/sdk part of this at dotnet/sdk#49564.

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!

Copy link
Member

@CarnaViire CarnaViire left a comment

Choose a reason for hiding this comment

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

LGTM

MichalStrehovsky added a commit that referenced this pull request Jun 27, 2025
Control over this is moving from dotnet/runtime repo build time to publish time so we need to set a default that matches the old build-time setting.

Ref #117012
Ref dotnet/sdk#49564
MichalStrehovsky added a commit to MichalStrehovsky/xamarin-macios that referenced this pull request Jun 27, 2025
Control over this is moving from dotnet/runtime repo build time to publish time so we need to set a default that matches the old build-time setting.

Ref dotnet/runtime#117012
Ref dotnet/sdk#49564
MichalStrehovsky added a commit to dotnet/sdk that referenced this pull request Jun 27, 2025
Control over this is moving from dotnet/runtime repo build time to publish time so we need to set a default that matches the old build-time setting.

Ref dotnet/runtime#117012
Ref #49564
MichalStrehovsky added a commit to MichalStrehovsky/android that referenced this pull request Jun 27, 2025
Control over this is moving from dotnet/runtime repo build time to publish time so we need to set a default that matches the old build-time setting.

Ref dotnet/runtime#117012
Ref dotnet/sdk#49564
@MichalStrehovsky
Copy link
Member Author

MichalStrehovsky commented Jun 27, 2025

rolfbjarne pushed a commit to dotnet/macios that referenced this pull request Jun 27, 2025
Control over this is moving from dotnet/runtime repo build time to publish time so we need to set a default that matches the old build-time setting.

Ref dotnet/runtime#117012
Ref dotnet/sdk#49564
MichalStrehovsky added a commit to dotnet/sdk that referenced this pull request Jun 27, 2025
Control over this is moving from dotnet/runtime repo build time to publish time so we need to set a default that matches the old build-time setting.

Ref dotnet/runtime#117012
Ref #49564
jonathanpeppers pushed a commit to dotnet/android that referenced this pull request Jun 27, 2025
Context: dotnet/runtime#117012
Context: dotnet/sdk#49564

Control over this is moving from dotnet/runtime repo build time to
publish time so we need to set a default that matches the old build-time setting.
@MichalStrehovsky MichalStrehovsky merged commit ecdfb14 into dotnet:main Jul 2, 2025
82 of 87 checks passed
@MichalStrehovsky MichalStrehovsky deleted the fix77420 branch July 2, 2025 05:47
rolfbjarne added a commit to dotnet/macios that referenced this pull request Jul 3, 2025
Control over this is moving from dotnet/runtime repo build time to publish time so we need to set a default that matches the old build-time setting.

Ref dotnet/runtime#117012
Ref dotnet/sdk#49564

This is a re-creation of #23221 using origin, since we can't build PRs from forks.

---------

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Net.Http linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding a trimming Feature Switch for Http3Support
7 participants