Skip to content

Send requests without a payload without a body or content type - #78

Merged
djthorpe merged 1 commit into
mainfrom
djt/1102/no-body-type
Nov 2, 2026
Merged

djthorpe merged 1 commit into
mainfrom
djt/1102/no-body-type

Conversation

@djthorpe

@djthorpe djthorpe commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

NewRequest and NewRequestEx return a payload that's an io.Reader with nothing to read. DoWithContext passed it to http.NewRequestWithContext as the request body, and because the body wasn't nil, every request without a payload was sent with Content-Type: application/json. That included GET, HEAD, POST and DELETE. Some servers refuse a GET or HEAD with a content type.

DoWithContext now sends a request without a body when its payload is one of go-client's own requests with no buffer, so it has no content type. JSON payloads, and other payload types such as streaming and multipart, are unchanged.

Tests: TestDoContentType in do_test.go checks that GET, HEAD, POST and DELETE without a payload arrive with no Content-Type, no length and no body, and that a JSON request still sends application/json and its body. It fails without the fix.

go test ./... passes, apart from pkg/homeassistant, whose tests call a live server (hay.mutablelogic.com) that doesn't resolve from here. They fail the same way on main.

NewRequest and NewRequestEx return a payload which is a reader with
nothing to read, which was sent as the body, so every GET, HEAD, POST
and DELETE without a payload had Content-Type: application/json, which
some servers refuse a GET or HEAD for. Send it without a body, so it has
no content type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 12:05
@djthorpe djthorpe self-assigned this Nov 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the change to omit bodies and automatic Content-Type headers from payload-free requests.

No open issues 🎉

What changed in this PR

This PR fixes how the client sends its own payload-free requests, omitting the body and automatic Content-Type header so servers do not reject otherwise valid GET or HEAD requests.

Changes:

  • Pass a nil body for built-in requests with no buffer, leaving JSON and other payload types unchanged.
  • Add regression tests for payload-free GET, HEAD, POST, and DELETE requests, plus JSON payload preservation.
File Description
do_test.go Tests absent content type and empty bodies, and verifies JSON requests remain intact.
client.go Uses a nil body for built-in requests without a payload buffer.

Review effort: Balanced

@djthorpe
djthorpe merged commit 309507c into main Nov 2, 2026
5 checks passed
@djthorpe
djthorpe deleted the djt/1102/no-body-type branch November 2, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants