Skip to content

fix: prevent StreamWriter from disposing HttpResponse.Body in ConfigurableResponseNegotiator#4

Merged
gimlichael merged 2 commits intov1.0.0/initialfrom
copilot/sub-pr-1-another-one
Mar 1, 2026
Merged

fix: prevent StreamWriter from disposing HttpResponse.Body in ConfigurableResponseNegotiator#4
gimlichael merged 2 commits intov1.0.0/initialfrom
copilot/sub-pr-1-another-one

Conversation

Copy link

Copilot AI commented Mar 1, 2026

StreamWriter constructed directly over HttpResponse.Body disposes the underlying response stream when the writer is disposed, which can corrupt the ASP.NET Core response pipeline.

Change

Added leaveOpen: true to the StreamWriter constructor, with bufferSize: -1 to preserve the default buffer size:

// Before
await using var textWriter = new StreamWriter(res.Body, encoding);

// After
await using var textWriter = new StreamWriter(res.Body, encoding, bufferSize: -1, leaveOpen: true);

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…se.Body

Co-authored-by: gimlichael <8550919+gimlichael@users.noreply.github.com>
Copilot AI changed the title [WIP] Update pull request based on review feedback fix: prevent StreamWriter from disposing HttpResponse.Body in ConfigurableResponseNegotiator Mar 1, 2026
@gimlichael gimlichael marked this pull request as ready for review March 1, 2026 22:39
Copilot AI review requested due to automatic review settings March 1, 2026 22:39
@gimlichael gimlichael merged commit 7e405e0 into v1.0.0/initial Mar 1, 2026
2 checks passed
@gimlichael gimlichael deleted the copilot/sub-pr-1-another-one branch March 1, 2026 22:40
Copy link

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

Prevents ConfigurableResponseNegotiator from accidentally closing HttpResponse.Body by ensuring the StreamWriter does not dispose the underlying response stream, avoiding corruption of the ASP.NET Core response pipeline.

Changes:

  • Construct StreamWriter with leaveOpen: true when writing to HttpResponse.Body.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants