net/http: document which headers Request.Write handles specially

Document that Header values for Host, Content-Length,
Transfer-Encoding, and Trailer are not used by Write, as these
are derived from other Request fields. Also document that
User-Agent defaults to "Go-http-client/1.1" if not set in Header.

Fixes #68635

Change-Id: Ie182777ae094657cf3971fed989af1bd5e875d9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/741442
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
kovan
2026-02-27 23:13:56 +01:00
committed by Gopher Robot
parent c43088c7a6
commit 3fc4af70d0

View File

@@ -558,6 +558,11 @@ const defaultUserAgent = "Go-http-client/1.1"
// If Body is present, Content-Length is <= 0 and [Request.TransferEncoding]
// hasn't been set to "identity", Write adds "Transfer-Encoding:
// chunked" to the header. Body is closed after it is sent.
//
// Header values for Host, Content-Length, Transfer-Encoding,
// and Trailer are not used; these are derived from other Request fields.
// If the Header does not contain a User-Agent value, Write uses
// "Go-http-client/1.1".
func (r *Request) Write(w io.Writer) error {
return r.write(w, false, nil, nil)
}