]> Cypherpunks repositories - gostls13.git/commit
net/http, net/http/httptrace: make Transport support 1xx responses properly
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 6 Jun 2018 22:50:01 +0000 (22:50 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 12 Jun 2018 13:42:28 +0000 (13:42 +0000)
commitd88b13786d3f1645ee59c2be555cb18cf49fe2e5
treecca0d332ec4d5eb4b88b58105bf9456147a70fdd
parent29b631e6f4fb3729cf4b369bcf47316f0d426845
net/http, net/http/httptrace: make Transport support 1xx responses properly

Previously the Transport had good support for 100 Continue responses,
but other 1xx informational responses were returned as-is.

But per https://tools.ietf.org/html/rfc7231#section-6.2:

> A client MUST be able to parse one or more 1xx responses received
> prior to a final response, even if the client does not expect one. A
> user agent MAY ignore unexpected 1xx responses.

We weren't doing that. Instead, we were returning any 1xx that wasn't
100 as the final result.

With this change we instead loop over up to 5 (arbitrary) 1xx
responses until we find the final one, returning an error if there's
more than 5. The limit is just there to guard against malicious
servers and to have _some_ limit.

By default we ignore the 1xx responses, unless the user defines the
new httptrace.ClientTrace.Got1xxResponse hook, which is an expanded
version of the previous ClientTrace.Got100Continue.

Still remaining:

* httputil.ReverseProxy work. (From rfc7231#section-6.2: "A proxy MUST
  forward 1xx responses unless the proxy itself requested the
  generation of the 1xx response."). Which would require:

* Support for an http.Handler to generate 1xx informational responses.

Those can happen later. Fixing the Transport to be resilient to others
using 1xx in the future without negotiation (as is being discussed
with HTTP status 103) is most important for now.

Updates #17739

Change-Id: I55aae8cd978164643fccb9862cd60a230e430486
Reviewed-on: https://go-review.googlesource.com/116855
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/go/build/deps_test.go
src/net/http/httptrace/trace.go
src/net/http/transport.go
src/net/http/transport_test.go