Skip to content

fix: avoid attaching an empty body to raw api requests on retry - #728

Merged
mwbrooks merged 4 commits into
mainfrom
zimeg-fix-api-raw-request-empty-body
Oct 28, 2026
Merged

mwbrooks merged 4 commits into
mainfrom
zimeg-fix-api-raw-request-empty-body

Conversation

@zimeg

@zimeg zimeg commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Changelog

slack api requests without a body are now sent with Content-Length: 0 instead of an empty chunked body.

Summary

This pull request stops the RawRequest retry loop from attaching an empty body to requests that were made without one.

  • The loop reattached io.NopCloser(bytes.NewReader(data)) on every attempt, even when data was empty, so a POST without a body was sent with Transfer-Encoding: chunked and a zero-length chunk.
  • Requests without a body now use http.NoBody, and ContentLength is set from the buffered body so retries resend it with an accurate length.
  • GET and HEAD requests 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 --verbose output, which doesn't print request headers, and --apihost requires HTTPS so a local listener can't capture the request. To compare with main:

  • Run git checkout main -- internal/api/raw_request.go then go test ./internal/api/ -run Test_RawRequest_RetryOnTooManyRequests -v and confirm it fails with content lengths of -1 from the chunked body.
  • Run git checkout HEAD -- internal/api/raw_request.go and confirm the same test passes with content lengths of 0.
  • slack api api.test --no-auth and slack api api.test foo=bar --no-auth still return {"ok":true,"args":{}} and {"ok":true,"args":{"foo":"bar"}}.

Notes

Requirements

πŸ€– Generated with Claude Code

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>
@zimeg zimeg added this to the Next Release milestone Oct 27, 2026
@zimeg zimeg added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch Use on pull requests to describe the release version increment labels Oct 27, 2026
@zimeg zimeg self-assigned this Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 78.11%. Comparing base (b28e0ca) to head (826e240).

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.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zimeg
zimeg marked this pull request as ready for review October 28, 2026 00:36
@zimeg
zimeg requested a review from a team as a code owner October 28, 2026 00:36
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg zimeg added the changelog Use on updates to be included in the release notes label Oct 28, 2026
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

βœ… Thanks @zimeg!

}
}

request.ContentLength = int64(len(data))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mwbrooks
mwbrooks enabled auto-merge (squash) October 28, 2026 22:04
@mwbrooks
mwbrooks merged commit 07ab1ca into main Oct 28, 2026
13 checks passed
@mwbrooks
mwbrooks deleted the zimeg-fix-api-raw-request-empty-body branch October 28, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented changelog Use on updates to be included in the release notes semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants