Skip to content

Fix HttpLoggingMiddleware Request/Response bodies logging in case of stream being closed by a subsequent middleware #61490

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ExtraClock
Copy link

Fix HttpLoggingMiddleware Request/Response bodies logging in case of stream being closed by a subsequent middleware (#61489)

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Preserve buffer contents until it is consumed by the HttpLoggingMiddleware

Description

Fixes #61489

When the subsequent middleware closes request/response stream, the BufferingStream calls Reset which leads to an empty body being logged.

The request stream might be closed if the subsequent middleware follows the ContentLength header to sense the end of the stream (instead of reading it to the end).

The response stream might be closed without any additional preconditions, just because the subsequent middleware decided to do so.

A real-life example of such a middleware is CoreWCF BasicHttpBinding: inputStream.Close, _outputStream.Close

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares label Apr 14, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 14, 2025
Copy link
Contributor

Thanks for your PR, @@ExtraClock. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@ExtraClock
Copy link
Author

@dotnet-policy-service agree

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HttpLogging drops Request/Response bodies if Stream has been closed
1 participant