Skip to content

Comments

Expose HTTP.sys kernel response buffering control for HttpListener on Windows#124720

Open
karimsalem1 wants to merge 1 commit intodotnet:mainfrom
karimsalem1:main
Open

Expose HTTP.sys kernel response buffering control for HttpListener on Windows#124720
karimsalem1 wants to merge 1 commit intodotnet:mainfrom
karimsalem1:main

Conversation

@karimsalem1
Copy link

This PR adds an opt-in AppContext switch to enable kernel response buffering in HttpListener (Windows implementation only). When enabled, the flag HTTP_SEND_RESPONSE_FLAG_BUFFER_DATA is set on all calls to HttpSendHttpResponse and HttpSendResponseEntityBody (consistent with Win32 docs). This mirrors the behavior for setting the HttpSysOptions.EnableKernelResponseBuffering flag in ASP.NET HTTP.sys code.

Motivation in issue #123425.

Sample usage:

AppContext.SetSwitch("System.Net.HttpListener.EnableKernelResponseBuffering", true);

using var listener = new HttpListener();
listener.Prefixes.Add("http://localhost:8080/");
listener.Start();

Console.WriteLine("Listening...");
while (true)
{
    var context = await listener.GetContextAsync().ConfigureAwait(false);
    _ = Task.Run(() => HandleRequestAsync(context));
}

Notes:

  • No public API changes
  • Default behavior remains unchanged
  • Since API is internal, tests use reflection to validate flag behavior.
  • Added dedicated Windows-only test classes for HttpListener and HttpResponseStream, and consolidated existing Windows-only tests there for consistency.

TODO: add manual validation repro showing perf improvements using this feature

Thanks @ManickaP for all the help!

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 22, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Feb 22, 2026

No public API changes

AppContext switches are de-facto public APIs, just a different kind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Net.Http community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants