fix: Buffer HTTP response content before logging to prevent stream consumption#1731
Conversation
Fixes #1530 Added comprehensive XML documentation for: - Interface summary describing certificate retrieval functionality - GetCertificateBySubject method with parameter and return docs - GetCertificateByThumbprint method with parameter and return docs - GetCertificateBySerialNumber method with parameter and return docs - GetCertificateBy method with parameter and return docs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…nsumption (#1610) When logging HTTP responses, calling ReadAsStringAsync() on the response content consumes the stream, making it unreadable by subsequent code. By calling LoadIntoBufferAsync() first, we ensure the content is buffered and can be read multiple times. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryAdds XML documentation to ICertificates interface and fixes response body stream consumption issue (#1610) by buffering responses before logging. Critical IssuesNone found ✅ SuggestionsPerformance consideration for response bufferingLocation: src/ModularPipelines/Http/ResponseLoggingHttpHandler.cs:21-23 The fix correctly addresses issue #1610 by calling
Impact: For pipelines that handle large file downloads or API responses with body logging disabled, this adds unnecessary memory pressure. Possible optimization: Recommendation: Consider documenting this behavior (that response logging buffers all responses) or track as a future optimization. For now, the fix is correct and safe - it prioritizes correctness over performance, which is the right trade-off for a bug fix. Overall verdict: The changes are good. The buffering fix correctly solves the stream consumption bug using the approach suggested in issue #1610. The documentation additions are clear and helpful. Verdict✅ APPROVE - No critical issues |
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #1610 by buffering HTTP response content before logging to prevent stream consumption, and adds comprehensive XML documentation to the ICertificates interface.
- Fixes HTTP response body stream consumption issue in logging handler
- Adds XML documentation to ICertificates interface methods
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ModularPipelines/Http/ResponseLoggingHttpHandler.cs | Adds LoadIntoBufferAsync() call before logging to ensure response content can be read multiple times |
| src/ModularPipelines/Context/ICertificates.cs | Adds XML documentation to interface and methods, removes redundant 'public' modifiers from interface members |
| // 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); |
There was a problem hiding this comment.
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.
| await response.Content.LoadIntoBufferAsync().ConfigureAwait(false); | |
| if (response.Content is not null) | |
| { | |
| await response.Content.LoadIntoBufferAsync().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); |
There was a problem hiding this comment.
The fix for issue #1610 (buffering response content before logging) lacks test coverage. Consider adding a test that verifies the response body can still be read after logging, which would prevent regression of this bug. The test should make an HTTP request, enable response logging, and then verify the response body is still readable.
Summary
LoadIntoBufferAsync()on response content before logging to ensure the stream is buffered and can be read multiple timesReadAsStringAsync()in the logger consumes the stream, making it unreadable by subsequent codeTest plan
🤖 Generated with Claude Code