Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Servers/HttpSys/test/FunctionalTests/ResponseBodyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public async Task ResponseBody_WriteContentLength_PassedThrough()
using (Utilities.CreateHttpServer(out address, async httpContext =>
{
httpContext.Features.Get<IHttpBodyControlFeature>().AllowSynchronousIO = true;
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The PR description mentions a bug filed on the http.sys team and that this is a workaround, but there is no code comment, issue link, or documentation explaining what the http.sys bug is, why spaces in the Content-Length header value trigger it, or when this workaround can be removed. Consider adding a comment with a reference to the filed bug to help future maintainers understand why the spaces were removed.

Suggested change
httpContext.Features.Get<IHttpBodyControlFeature>().AllowSynchronousIO = true;
httpContext.Features.Get<IHttpBodyControlFeature>().AllowSynchronousIO = true;
// This test intentionally uses a Content-Length value without any spaces.
// There is a filed http.sys bug where Content-Length values containing spaces
// can be parsed or handled incorrectly. The product code works around that bug
// by normalizing/removing spaces before sending the header. This test verifies
// that a clean Content-Length value is passed through unchanged by http.sys.
// When the underlying http.sys bug is fixed and the workaround removed, this
// test should be revisited to ensure behavior remains correct.

Copilot uses AI. Check for mistakes.
httpContext.Response.Headers["Content-lenGth"] = " 30 ";
httpContext.Response.Headers["Content-lenGth"] = "30";
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The workaround for the http.sys bug has been applied only to this test method, but other test methods in the same file (lines 239, 253, 268, and 289) still use Content-Length header values with leading and trailing spaces. If this is a workaround for an http.sys bug, it should be consistently applied to all test methods that set the Content-Length header, or there should be a comment explaining why only this specific test needs the workaround.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

@BrennanConroy Do we need to fix the other cases?

Stream stream = httpContext.Response.Body;
stream.EndWrite(stream.BeginWrite(new byte[10], 0, 10, null, null));
stream.Write(new byte[10], 0, 10);
Expand All @@ -236,7 +236,7 @@ public async Task ResponseBody_WriteContentLengthNoneWritten_Throws()
string address;
using (Utilities.CreateHttpServer(out address, httpContext =>
{
httpContext.Response.Headers["Content-lenGth"] = " 20 ";
httpContext.Response.Headers["Content-lenGth"] = "20";
return Task.FromResult(0);
}, LoggerFactory))
{
Expand All @@ -250,7 +250,7 @@ public async Task ResponseBody_WriteContentLengthNotEnoughWritten_Throws()
string address;
using (Utilities.CreateHttpServer(out address, httpContext =>
{
httpContext.Response.Headers["Content-lenGth"] = " 20 ";
httpContext.Response.Headers["Content-lenGth"] = "20";
return httpContext.Response.Body.WriteAsync(new byte[5], 0, 5);
}, LoggerFactory))
{
Expand All @@ -265,7 +265,7 @@ public async Task ResponseBody_WriteContentLengthTooMuchWritten_Throws()
string address;
using (Utilities.CreateHttpServer(out address, async httpContext =>
{
httpContext.Response.Headers["Content-lenGth"] = " 10 ";
httpContext.Response.Headers["Content-lenGth"] = "10";
await httpContext.Response.Body.WriteAsync(new byte[5], 0, 5);
await Assert.ThrowsAsync<InvalidOperationException>(() =>
httpContext.Response.Body.WriteAsync(new byte[6], 0, 6));
Expand All @@ -286,7 +286,7 @@ public async Task ResponseBody_WriteContentLengthExtraWritten_Throws()
try
{
httpContext.Features.Get<IHttpBodyControlFeature>().AllowSynchronousIO = true;
httpContext.Response.Headers["Content-lenGth"] = " 10 ";
httpContext.Response.Headers["Content-lenGth"] = "10";
httpContext.Response.Body.Write(new byte[10], 0, 10);
httpContext.Response.Body.Write(new byte[9], 0, 9);
requestThrew.SetResult(false);
Expand Down
Loading