Fix Go SDK Content-Type on GET requests#334
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds safeguards to avoid sending a Content-Type header on bodyless GET requests, aligning request headers with HTTP semantics and preventing confusing/incorrect metadata.
Changes:
- Update client request building to only set
Content-Type: application/jsonwhen a body is present. - Introduce a
requestHasBodyhelper used by the generated-client request path. - Add tests covering GET (no
Content-Type) and POST (JSONContent-Type) behavior, plus a higher-level search test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| go/pkg/basecamp/search_test.go | Adds a regression test ensuring Search() GET requests don’t send Content-Type. |
| go/pkg/basecamp/client_test.go | Adds unit tests asserting correct header behavior for GET vs POST. |
| go/pkg/basecamp/client.go | Changes header-setting logic to be body-aware; adds requestHasBody helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
1 issue found across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
Fixed — addressed the review feedback by adding method assertions, using http.StatusOK, and aligning body detection. |
|
Fixed — added the GET method assertion identified by cubic. |
|
Fixed — addressed the latest Copilot review feedback by preserving existing Content-Type values and avoiding t.Fatalf in httptest handler goroutines. |
c0b8fe1 to
0d03f1d
Compare
Summary
Content-Type: application/jsonon bodyless Go SDK requestsAccept: application/jsonon requests and keepContent-Typefor JSON bodiesWhy
Content-Typedescribes the request body. Bodyless GET requests use URL query parameters, and sendingContent-Type: application/jsoncauses/search.json?q=...to return unfiltered results.Fixes #324.
Tests
go test ./go/pkg/basecampgo test ./go/...Summary by cubic
Stop sending
Content-Type: application/jsonon bodyless GET requests in the Go SDK (go/pkg/basecamp) to fix unfiltered/search.jsonresults (Fixes #324).Accept: application/jsonstays;Content-Typeis only set when a JSON body exists and isn’t already set.requestHasBodyand use it in the generated client andsingleRequestsoContent-Typeis only set with a body; always setAccept: application/json.Content-Type, POST sets JSONContent-Type, POST preserves an existingContent-Typevia an auth strategy and asserts it was empty before auth runs, and Search GET checks headers andqparam.Written for commit 767a8ff. Summary will update on new commits.