Repository navigation
fix: send query params instead of a body for GET and HEAD requests from slack api - #727
Conversation
โฆom slack api Many proxies and CDNs reject GET or HEAD requests that include a body, but "slack api -X GET" form-encoded key=value args and the token into one. These are now sent in the query string with the token in the Authorization header. RawRequest also no longer attaches an empty body when retrying. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Reportโ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #727 +/- ##
=======================================
Coverage 78.10% 78.11%
=======================================
Files 238 238
Lines 18097 18114 +17
=======================================
+ Hits 14135 14150 +15
- Misses 3962 3964 +2 โ View full report in Codecov by Harness. ๐ New features to boost your workflow:
|
zimeg
left a comment
There was a problem hiding this comment.
๐ฃ Notes to me - the self for here.
โฆequest Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
zimeg
left a comment
There was a problem hiding this comment.
Getting to a good place but another comment to make.
| } | ||
| bodyReader = strings.NewReader(formData) | ||
| token = "" | ||
| case len(params) == 1 && (strings.HasPrefix(params[0], "{") || strings.HasPrefix(params[0], "[")): |
There was a problem hiding this comment.
๐ note: Refactored up to L161 at the time of writing.
| bodyReader = strings.NewReader(values.Encode()) | ||
| token = "" | ||
| case bodyless: | ||
| // Send no body and keep the token for the Authorization header |
There was a problem hiding this comment.
๐ฆ note: This is set in our request:
slack-cli/internal/api/raw_request.go
Lines 62 to 64 in 1fc888b
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
| assert.Equal(t, tc.expectedQuery, receivedQuery) | ||
| if tc.assertNoBody { | ||
| assert.Empty(t, receivedContentType) | ||
| assert.Zero(t, receivedContentLength) |
There was a problem hiding this comment.
praise: Thanks for extending the table test instead of adding new ones. Checking ContentLength along with the body is a nice way to prove nothing goes over the wire.
Changelog
slack api --method GETnow sendskey=valuearguments and--dataas query parameters, with the token in theAuthorizationheader, instead of form-encoding them into a request body.Summary
This pull request stops
slack apifrom attaching a request body toGETandHEADrequests, since many proxies and CDNs reject these requests when a body is included.key=valuearguments and--dataare sent in the query string forGETandHEAD, and the token moves from the body to theAuthorization: Bearerheader.--jsonor a JSON argument is still sent as given, and the API response is returned unchanged.GETandHEAD, and the "No args" line now matches the form-encoded token sent withPOST.Testing
slack api api.test foo=bar -X GET --no-auth --verboseshowsGET https://slack.com/api/api.test?foo=barwith<no body>and returns{"ok":true,"args":{"foo":"bar"}}.slack api auth.test -X GET --token <token> --verboseshows no request body and authenticates with the header token.slack api chat.postMessage channel=<channel> text=hi --token <token>still sends a form-encoded body withPOST.slack api api.test --json '{"foo":"bar"}' -X GET --no-authsends the JSON body and prints the API response as is.Notes
RawRequestretry loop also attaches an empty reader to requests without a body. Go's transport drops this forGETandHEAD, so it's fixed separately in fix: avoid attaching an empty body to raw api requests on retryย #728 forPOST.DoWithRetryuses the same body-reattach loop, but is left as is: itsGETcallers pass anilbody that Go's transport drops on the wire, and itsPOSTcallers always have a body.GETorHEADis kept as an explicit choice for now and might be worth revisiting.Requirements
๐ค Generated with Claude Code