Skip to content

Comments

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

Open
karimsalem1 wants to merge 2 commits intodotnet:mainfrom
karimsalem1:main
Open

Expose HTTP.sys kernel response buffering control for HttpListener on Windows#124720
karimsalem1 wants to merge 2 commits 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.

Assert.Equal(expectedResponse, clientString);
}
}
}).Dispose();
Copy link
Member

Choose a reason for hiding this comment

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

Please use DisposeAsync if you're invoking an async method. It's an extension from https://github.com/dotnet/runtime/blob/main/src/libraries/Common/tests/System/Net/RemoteExecutorExtensions.cs

We were hitting timeouts from thread pool starvation on limited CI machines due to Dispose here doing sync-over-async.

TLDR explanation: dotnet/arcade#14807

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.

One comment otherwise LGTM. I'll await the manual validation results.

Thanks!

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.

3 participants