aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/response.go
AgeCommit message (Collapse)Author
2026-02-03net/http: prevent blocking when draining response body after it has been closedNicholas S. Husin
Previously, draining the response body after it has been closed causes Response.Body.Close to block for longer than it otherwise would. In a worst-case scenario, this means that we are incurring a 50 ms delay for each HTTP/1 request that we make. This CL makes sure that a response body is drained asynchronously and updates relevant documentations to reflect the current behavior. For #77370 Change-Id: I2486961bc1ea3d43d727d0aabc7a6ca7dfb166ee Reviewed-on: https://go-review.googlesource.com/c/go/+/741222 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <husin@google.com>
2024-01-10net: add available godoc linkcui fliter
Change-Id: Ib7c4baf0247c421954aedabfbb6a6af8a08a8936 Reviewed-on: https://go-review.googlesource.com/c/go/+/540021 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-04-15net/http: optimize StatusText implementationJoão Penteado
The current implementation, although more succinct, relies on a runtime lookup to a "constant" unexported map (which also needs to be initialized at runtime). The proposed implementation is able to be optimized by the compiler at build-time, resulting in *much* more efficient instructions. Additionally, unused string literals may even be removed altogether from the generated binary in some cases. This change is fully backwards-compatible behavior-wise with the existing implementation. Change-Id: I36450320aacff5b322195820552f2831d4fecd52 GitHub-Last-Rev: e2058f132ef7a193529d4b0e84329ac93e5d1dcb GitHub-Pull-Request: golang/go#49811 Reviewed-on: https://go-review.googlesource.com/c/go/+/367201 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-10-06all: use bytes.Cut, strings.CutRuss Cox
Many uses of Index/IndexByte/IndexRune/Split/SplitN can be written more clearly using the new Cut functions. Do that. Also rewrite to other functions if that's clearer. For #46336. Change-Id: I68d024716ace41a57a8bf74455c62279bde0f448 Reviewed-on: https://go-review.googlesource.com/c/go/+/351711 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-14net/http: attempt deadlock fix in TestDisableKeepAliveUpgradeAnmol Sethi
1. The test now checks the response status code. 2. The transport has been changed to not set "Connection: Close" if DisableKeepAlive is set and the request is a HTTP/1.1 protocol upgrade. Updates #43073 Change-Id: I9977a18b33b8747ef847a8d11bb7b4f2d8053b8c GitHub-Last-Rev: f809cebb139df4f5560a8456973351c95a3dfa97 GitHub-Pull-Request: golang/go#43086 Reviewed-on: https://go-review.googlesource.com/c/go/+/276375 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Trust: Dmitri Shuralyov <dmitshur@golang.org>
2020-12-01net/http: allow upgrading non keepalive connectionsAnmol Sethi
If one was using http.Transport with DisableKeepAlives and trying to upgrade a connection against net/http's Server, the Server would not allow a "Connection: Upgrade" header to be written and instead override it to "Connection: Close" which would break the handshake. This change ensures net/http's Server does not override the connection header for successful protocol switch responses. Fixes #36381. Change-Id: I882aad8539e6c87ff5f37c20e20b3a7fa1a30357 GitHub-Last-Rev: dc0de83201dc26236527b68bd49dffc53dd0389b GitHub-Pull-Request: golang/go#36382 Reviewed-on: https://go-review.googlesource.com/c/go/+/213277 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-05-01net/http: remove badStringError, make some unexported structs non-comparableBrad Fitzpatrick
Reduces binary size by 4K, not counting the http2 changes (in CL 231119) that'll be bundled into this package in the future. Updates golang/go#38782 Change-Id: Id360348707e076b8310a8f409e412d68dd2394b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/231118 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-08-05net/http: fix typo in Response.Body's docShivani Singhal
Fixes #33453. Change-Id: If0aa48f953633690884ddcff033b3be6d1d66443 Reviewed-on: https://go-review.googlesource.com/c/go/+/188541 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-03-28net/http: fix typo in Response.Body field docsBrad Fitzpatrick
Fixes #31096 Change-Id: I5b36bfc6d18eb8c1bbf15abcd92b0e6559cda3c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/169683 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-03-11all: move internal/x to vendor/golang.org/x and revendor using 'go mod vendor'Bryan C. Mills
This also updates the vendored-in versions of several packages: 'go mod vendor' selects a consistent version of each module, but we had previously vendored an ad-hoc selection of packages. Notably, x/crypto/hkdf was previously vendored in at a much newer commit than the rest of x/crypto. Bringing the rest of x/crypto up to that commit introduced an import of golang.org/x/sys/cpu, which broke the js/wasm build, requiring an upgrade of x/sys to pick up CL 165749. Updates #30228 Updates #30241 Updates #25822 Change-Id: I5b3dbc232b7e6a048a158cbd8d36137af1efb711 Reviewed-on: https://go-review.googlesource.com/c/go/+/164623 Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-11-29vendor/golang_org/x: move to internal/xBryan C. Mills
Packages in vendor/ directories have a "vendor/" path prefix in GOPATH mode, but intentionally do not in module mode. Since the import path is embedded in the compiled output, changing that path invalidates cache entries and causes cmd/go to try to rebuild (and reinstall) the vendored libraries, which will fail if the directory containing those libraries is read-only. If I understood correctly, this is the approach Russ suggested as an alternative to https://golang.org/cl/136138. Fixes #27285 Fixes #26988 Change-Id: I8a2507fa892b84cde0a803aaa79e460723da572b Reviewed-on: https://go-review.googlesource.com/c/147443 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2018-08-25net/http: make Transport return Writable Response.Body on protocol switchBrad Fitzpatrick
Updates #26937 Updates #17227 Change-Id: I79865938b05c219e1947822e60e4f52bb2604b70 Reviewed-on: https://go-review.googlesource.com/131279 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-27net/http/httptrace: expose request headers for http/1.1Meir Fischer
Some headers, which are set or modified by the http library, are not written to the standard http.Request.Header and are not included as part of http.Response.Request.Header. Exposing all headers alleviates this problem. This is not a complete solution to 19761 since it does not have http/2 support. Updates #19761 Change-Id: Ie8d4f702f4f671666b120b332378644f094e288b Reviewed-on: https://go-review.googlesource.com/67430 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-20net/http: use RFC 723x as normative reference in docsDavid Url
Replace references to the obsoleted RFC 2616 with references to RFC 7230 through 7235, to avoid unnecessary confusion. Obvious inconsistencies are marked with todo comments. Updates #21974 Change-Id: I8fb4fcdd1333fc5193b93a2f09598f18c45e7a00 Reviewed-on: https://go-review.googlesource.com/94095 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-01-05net/http: soften wording around when the Transport reuses connectionsBrad Fitzpatrick
The docs were too specific. Make it vaguer. There are conditions for which the Transport will try to reuse a connection anyway, even if the Response Body isn't read to EOF or closed, but we don't need to get into all the details in the docs. Fixes #22954 Change-Id: I3b8ae32aeb1a61b396d0026e129552afbfecceec Reviewed-on: https://go-review.googlesource.com/86276 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-28net/http: document streaming nature of Response.BodyBrad Fitzpatrick
Fixes #22873 Change-Id: Ib2b7ee42a23b84db21cdfa693b62d5e6fbfdb54e Reviewed-on: https://go-review.googlesource.com/80075 Reviewed-by: Tom Bergan <tombergan@google.com>
2017-04-27net/http: close resp.Body when error occurred during redirectionWeichao Tang
Fixes #19976 Change-Id: I48486467066784a9dcc24357ec94a1be85265a6f Reviewed-on: https://go-review.googlesource.com/40940 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-04-17net/http: ignore extra space between response version and status codeAndy Balholm
Reading a response with a status line like "HTTP/1.0 401 Unauthorized" (with two spaces after the version) has been returning an error. Now the extra space will be ignored. Fixes #19989 Change-Id: I0c88a6ef7562ba80e2e2635be2070dd1b5b671a7 Reviewed-on: https://go-review.googlesource.com/40933 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-13net/http: document Response.Header values that are subordinate to other fieldsSameer Ajmani
I noticed that Content-Length may appear in http.Response.Header, but the docs say it should be omitted. Per discussion with bradfitz@, updating the docs to indicate that the struct fields are authoritative. Change-Id: Id1807ff9d4ba5de425d8b147205f29b18351230f Reviewed-on: https://go-review.googlesource.com/36842 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-22net/http: add NoBody, don't return nil from NewRequest on zero bodiesBrad Fitzpatrick
This is an alternate solution to https://golang.org/cl/31445 Instead of making NewRequest return a request with Request.Body == nil to signal a zero byte body, add a well-known variable that means explicitly zero. Too many tests inside Google (and presumably the outside world) broke. Change-Id: I78f6ecca8e8aa1e12179c234ccfb6bcf0ee29ba8 Reviewed-on: https://go-review.googlesource.com/31726 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2016-09-01net/http: omit Content-Length in Response.Write for 1xx or 204 statusMatt Layher
Per RFC 7230, Section 3.3.2: "A server MUST NOT send a Content-Length header field in any response with a status code of 1xx (Informational) or 204 (No Content).". Fixes #16942 Change-Id: I8006c76c126304e13618966e6eafb08a3885d3cd Reviewed-on: https://go-review.googlesource.com/28351 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-06-29net/http: be consistent about spelling of HTTP/1.xBrad Fitzpatrick
There was only one use of "HTTP/1.n" compared to "HTTP/1.x": h2_bundle.go:// "Just as in HTTP/1.x, header field names are strings of ASCII httputil/dump.go:// DumpRequest returns the given request in its HTTP/1.x wire httputil/dump.go:// intact. HTTP/2 requests are dumped in HTTP/1.x form, not in their response.go:// Write writes r to w in the HTTP/1.x server response format, server.go: // Request.Body. For HTTP/1.x requests, handlers should read any server.go:// The default HTTP/1.x and HTTP/2 ResponseWriter implementations server.go:// The default ResponseWriter for HTTP/1.x connections supports server.go:// http1ServerSupportsRequest reports whether Go's HTTP/1.x server server.go: // about HTTP/1.x Handlers concurrently reading and writing, like server.go: // HTTP/1.x from here on. transport.go: return fmt.Errorf("net/http: HTTP/1.x transport connection broken: %v", err) Be consistent. Change-Id: I93c4c873e500f51af2b4762055e22f5487a625ac Reviewed-on: https://go-review.googlesource.com/24610 Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-05-18net/http: allow Client.CheckRedirect to use most recent responseBrad Fitzpatrick
Fixes #10069 Change-Id: I3819ff597d5a0c8e785403bf9d65a054f50655a6 Reviewed-on: https://go-review.googlesource.com/23207 Reviewed-by: Russ Cox <rsc@golang.org>
2016-05-01net/http: add Response.Uncompressed boolBrad Fitzpatrick
The Transport's automatic gzip uncompression lost information in the process (the compressed Content-Length, if known). Normally that's okay, but it's not okay for reverse proxies which have to be able to generate a valid HTTP response from the Transport's provided *Response. Reverse proxies should normally be disabling compression anyway and just piping the compressed pipes though and not wasting CPU cycles decompressing them. So also document that on the new Uncompressed field. Then, using the new field, fix Response.Write to not inject a bogus "Connection: close" header when it doesn't see a transfer encoding or content-length. Updates #15366 (the http2 side remains, once this is submitted) Change-Id: I476f40aa14cfa7aa7b3bf99021bebba4639f9640 Reviewed-on: https://go-review.googlesource.com/22671 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-12all: standardize RFC mention formatDan Peterson
Standardize on space between "RFC" and number. Additionally change the couple "a RFC" instances to "an RFC." Fixes #15258 Change-Id: I2b17ecd06be07dfbb4207c690f52a59ea9b04808 Reviewed-on: https://go-review.googlesource.com/21902 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-05net/http: zero pad Response status codes to three digitsBrad Fitzpatrick
Go 1.6's HTTP/1.x Transport started enforcing that responses have 3 status digits, per the spec, but we could still write out invalid status codes ourselves if the called ResponseWriter.WriteHeader(0). That is bogus anyway, since the minimum status code is 1xx, but be a little bit less bogus (and consistent) and zero pad our responses. Change-Id: I6883901fd95073cb72f6b74035cabf1a79c35e1c Reviewed-on: https://go-review.googlesource.com/19130 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-03-02all: single space after period.Brad Fitzpatrick
The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-01-13net/http: reject non three digit status codes in ReadResponseEmmanuel Odeke
Change-Id: If4a90c4017ef4b5c9f497cf117c8ad62b7e15c62 Reviewed-on: https://go-review.googlesource.com/18501 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-12-17net/http: update Response.Trailer docBrad Fitzpatrick
I updated this in the previous commit (https://golang.org/cl/17931) but noticed a typo. and it still wasn't great. The Go 1.5 text was too brief to know how to use it: // Trailer maps trailer keys to values, in the same // format as the header. Change-Id: I33c49b6a4a7a3596735a4cc7865ad625809da900 Reviewed-on: https://go-review.googlesource.com/17932 Reviewed-by: Russ Cox <rsc@golang.org>
2015-12-17net/http: update bundled copy of http2, enable TestTrailersServerToClient testsBrad Fitzpatrick
This CL updates the bundled copy of x/net/http2 to include https://golang.org/cl/17930 and enables the previously-skipped tests TestTrailersServerToClient_h2 and TestTrailersServerToClient_Flush_h2. It also updates the docs on http.Response.Trailer to describe how to use it. No change in rules. Just documenting the old unwritten rules. (there were tests locking in the behavior, and misc docs and examples scattered about, but not on http.Response.Trailer itself) Updates #13557 Change-Id: I6261d439f6c0d17654a1a7928790e8ffed16df6c Reviewed-on: https://go-review.googlesource.com/17931 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Blake Mizerany <blake.mizerany@gmail.com>
2015-06-26net/http: add comment to exported ErrNoCookie and ErrNoLocation valuesMatt Layher
All other exported errors in net/http are commented. This change adds documentation to ErrNoCookie and ErrNoLocation to explain where they are returned, and why. Change-Id: I21fa0d070dd35256681ad0714000f238477d4af1 Reviewed-on: https://go-review.googlesource.com/11044 Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-28net/http: documentation updatesBrad Fitzpatrick
Fixes #10366 (how to set custom headers) Fixes #9836 (PATCH in PostForm) Fixes #9276 (generating a server-side Request for testing) Update #8991 (clarify Response.Write for now; export ReverseProxy's copy later?) Change-Id: I95a11bf3bb3eeeeb72775b6ebfbc761641addc35 Reviewed-on: https://go-review.googlesource.com/9410 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2014-12-13net/http: document Response.Body Read+Close interaction with keep-aliveBrad Fitzpatrick
Fixes #5645 Change-Id: Ifb46d6faf7ac838792920f6fe00912947478e761 Reviewed-on: https://go-review.googlesource.com/1531 Reviewed-by: David Symonds <dsymonds@golang.org>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.