-
-
Notifications
You must be signed in to change notification settings - Fork 21
fix: Buffer HTTP response content before logging to prevent stream consumption #1731
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,11 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage | |
| { | ||
| var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| // Buffer the response content so it can be read multiple times. | ||
| // Without this, reading the body for logging consumes the stream, | ||
| // making it unreadable by subsequent code. See issue #1610. | ||
| await response.Content.LoadIntoBufferAsync().ConfigureAwait(false); | ||
|
||
|
|
||
| await _httpLogger.PrintResponse(response, _logger).ConfigureAwait(false); | ||
|
|
||
| return response; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response.Content property could potentially be null, which would cause a NullReferenceException when calling LoadIntoBufferAsync(). Consider adding a null check before buffering the content.