Skip to content

Write no User-Agent when it is set to nil or the empty string - #28

Open
Mootjelh wants to merge 1 commit into
bogdanfinn:masterfrom
Mootjelh:empty-user-agent
Open

Write no User-Agent when it is set to nil or the empty string#28
Mootjelh wants to merge 1 commit into
bogdanfinn:masterfrom
Mootjelh:empty-user-agent

Conversation

@Mootjelh

@Mootjelh Mootjelh commented Sep 8, 2026

Copy link
Copy Markdown

For bogdanfinn/tls-client#140.

net/http sends no User-Agent when the header is set to nil or to the empty string, and the HTTP/2 path in this package does the same; the comment above didUA says so. The HTTP/1.1 writer did not. It added Go's own only when the key was missing, and a present, empty one then went out as an empty User-Agent: line. Measured through a proxy that records the CONNECT header lines as they arrive, from tls-client with WithConnectHeaders(http.Header{"User-Agent": {""}, ...}): Connection: keep-alive, Host: 127.0.0.1:..., User-Agent: with nothing after the colon.

The writer now leaves the header out of the write when it is present and empty, in either spelling, and still adds the default when it is missing. That is one exclude map handed to writeSubset, so the caller's header map is not touched beyond what write already did.

TestRequestWriteOmitsAnEmptyUserAgent covers both spellings with nil and with "", and the two controls: no header gives User-Agent: Go-http-client/1.1, a value goes out as given. On master it fails on the empty line.

For tls-client this means WithConnectHeaders(http.Header{"User-Agent": {""}}) sends a CONNECT with Host and nothing else, which is what #140 asks for, once the client pins a release with this in it.

net/http and the HTTP/2 path here send none; HTTP/1.1 wrote an empty
User-Agent: line.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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