Skip to content

Commit 107a6ef

Browse files
committed
net/http: document Request.Header and Request.Close more
Updates #14227 Change-Id: If39f11471ecd307c9483f64e73f9c89fe906ae71 Reviewed-on: https://go-review.googlesource.com/19222 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
1 parent 4d02b12 commit 107a6ef

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/net/http/request.go

+27-13
Original file line numberDiff line numberDiff line change
@@ -99,30 +99,37 @@ type Request struct {
9999
ProtoMajor int // 1
100100
ProtoMinor int // 0
101101

102-
// A header maps request lines to their values.
103-
// If the header says
102+
// Header contains the request header fields either received
103+
// by the server or to be sent by the client.
104104
//
105+
// If a server received a request with header lines,
106+
//
107+
// Host: example.com
105108
// accept-encoding: gzip, deflate
106109
// Accept-Language: en-us
107-
// Connection: keep-alive
110+
// fOO: Bar
111+
// foo: two
108112
//
109113
// then
110114
//
111115
// Header = map[string][]string{
112116
// "Accept-Encoding": {"gzip, deflate"},
113117
// "Accept-Language": {"en-us"},
114-
// "Connection": {"keep-alive"},
118+
// "Foo": {"Bar", "two"},
115119
// }
116120
//
117-
// HTTP defines that header names are case-insensitive.
118-
// The request parser implements this by canonicalizing the
119-
// name, making the first character and any characters
120-
// following a hyphen uppercase and the rest lowercase.
121+
// For incoming requests, the Host header is promoted to the
122+
// Request.Host field and removed from the Header map.
121123
//
122-
// For client requests certain headers are automatically
123-
// added and may override values in Header.
124+
// HTTP defines that header names are case-insensitive. The
125+
// request parser implements this by using CanonicalHeaderKey,
126+
// making the first character and any characters following a
127+
// hyphen uppercase and the rest lowercase.
124128
//
125-
// See the documentation for the Request.Write method.
129+
// For client requests, certain headers such as Content-Length
130+
// and Connection are automatically written when needed and
131+
// values in Header may be ignored. See the documentation
132+
// for the Request.Write method.
126133
Header Header
127134

128135
// Body is the request's body.
@@ -152,8 +159,15 @@ type Request struct {
152159
TransferEncoding []string
153160

154161
// Close indicates whether to close the connection after
155-
// replying to this request (for servers) or after sending
156-
// the request (for clients).
162+
// replying to this request (for servers) or after sending this
163+
// request and reading its response (for clients).
164+
//
165+
// For server requests, the HTTP server handles this automatically
166+
// and this field is not needed by Handlers.
167+
//
168+
// The client requests, setting this field prevents re-use of
169+
// TCP connections between requests to the same hosts, as if
170+
// Transport.DisableKeepAlives were set.
157171
Close bool
158172

159173
// For server requests Host specifies the host on which the

0 commit comments

Comments
 (0)