Add optional HTTP response body consumption checking with -check-consumption flag #75
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thank you for this excellent analysis tool!
Summary
As mentioned in issue #43, it would be helpful to check not only if
resp.Body.Close()is called, but also whether the response body is actually consumed. This PR implements an optional-check-consumptionflag to provide thisfunctionality.
Motivation
While the current tool ensures bodies are closed, checking consumption is also valuable for:
Implementation
Key Features
-check-consumptionflagSupported Consumption Patterns
io.Copy(io.Discard, resp.Body)io.ReadAll(resp.Body)/ioutil.ReadAll(resp.Body)json.NewDecoder(resp.Body)bufio.NewScanner(resp.Body)/bufio.NewReader(resp.Body)Documentation
Known Limitations
Since detecting all consumption patterns is challenging, some false positives may occur:
//nolint:bodyclosefor false positivesAll limitations are documented in the README with examples.
Compatibility
No impact on existing functionality - the new feature is completely opt-in via the
-check-consumptionflag.Note: This pull request includes commits generated with Claude Code assistance, but I have carefully reviewed and guided the implementation throughout the development process.
This enhancement helps developers write more robust HTTP client code while maintaining the tool's existing simplicity and reliability.