Repository navigation
fix: avoid attaching an empty body to raw api requests on retry - #728
Merged
Merged
Conversation
The retry loop in RawRequest always attached a reader to the request, so a POST without a body was sent with chunked transfer encoding. It now leaves requests without a body empty and keeps an accurate content length when a body is resent. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
2 tasks done
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #728 +/- ##
==========================================
+ Coverage 78.09% 78.11% +0.02%
==========================================
Files 238 238
Lines 18094 18097 +3
==========================================
+ Hits 14130 14137 +7
+ Misses 3964 3960 -4 β View full report in Codecov by Harness. π New features to boost your workflow:
|
zimeg
marked this pull request as ready for review
October 28, 2026 00:36
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
mwbrooks
approved these changes
Oct 28, 2026
| } | ||
| } | ||
|
|
||
| request.ContentLength = int64(len(data)) |
Member
There was a problem hiding this comment.
praise: Setting ContentLength once from the buffered body is a nice touch. Bodies from readers that http.NewRequest can't measure now get an accurate length too, not just the empty case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changelog
slack apirequests without a body are now sent withContent-Length: 0instead of an empty chunked body.Summary
This pull request stops the
RawRequestretry loop from attaching an empty body to requests that were made without one.io.NopCloser(bytes.NewReader(data))on every attempt, even whendatawas empty, so aPOSTwithout a body was sent withTransfer-Encoding: chunkedand a zero-length chunk.http.NoBody, andContentLengthis set from the buffered body so retries resend it with an accurate length.GETandHEADrequests were already sent without a body on the wire since Go's transport drops empty bodies for these methods, and this keeps that behavior explicit.Testing
The change isn't visible in
--verboseoutput, which doesn't print request headers, and--apihostrequires HTTPS so a local listener can't capture the request. To compare withmain:git checkout main -- internal/api/raw_request.gothengo test ./internal/api/ -run Test_RawRequest_RetryOnTooManyRequests -vand confirm it fails with content lengths of-1from the chunked body.git checkout HEAD -- internal/api/raw_request.goand confirm the same test passes with content lengths of0.slack api api.test --no-authandslack api api.test foo=bar --no-authstill return{"ok":true,"args":{}}and{"ok":true,"args":{"foo":"bar"}}.Notes
DoWithRetryuses the same reattach loop but is left as is since itsPOSTcallers always send a body.Requirements
π€ Generated with Claude Code