]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: remove invalid checks of Request.Proto* for outgoing requests
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 8 Jun 2017 21:43:54 +0000 (21:43 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 8 Jun 2017 23:54:01 +0000 (23:54 +0000)
The net/http package has long documented that Request.ProtoMajor and
Request.ProtoMinor are ignored for outgoing requests (HTTP/1.1 or
HTTP/2 is always used, never HTTP/1.0). There was one part in the code
that was actually checking 1.0 vs 1.1, but it appears to have been
harmless. Remove it.

Fixes #18407

Change-Id: I362ed6c47ca2de7a2fbca917ed3e866273cfe41f
Reviewed-on: https://go-review.googlesource.com/45155
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/http/request.go
src/net/http/transfer.go

index f1e71d8b43d543eb50dd8e4bb85ee84ed1bf7cda..699b31a14e788b98373670d08ea51025c1085c73 100644 (file)
@@ -349,18 +349,6 @@ func (r *Request) ProtoAtLeast(major, minor int) bool {
                r.ProtoMajor == major && r.ProtoMinor >= minor
 }
 
-// protoAtLeastOutgoing is like ProtoAtLeast, but is for outgoing
-// requests (see issue 18407) where these fields aren't supposed to
-// matter.  As a minor fix for Go 1.8, at least treat (0, 0) as
-// matching HTTP/1.1 or HTTP/1.0.  Only HTTP/1.1 is used.
-// TODO(bradfitz): ideally remove this whole method. It shouldn't be used.
-func (r *Request) protoAtLeastOutgoing(major, minor int) bool {
-       if r.ProtoMajor == 0 && r.ProtoMinor == 0 && major == 1 && minor <= 1 {
-               return true
-       }
-       return r.ProtoAtLeast(major, minor)
-}
-
 // UserAgent returns the client's User-Agent, if sent in the request.
 func (r *Request) UserAgent() string {
        return r.Header.Get("User-Agent")
index f87f80f51bc1ce27ff5370994aef3600549a52ad..8faff2d74a65bc0958575b49ed9ca73ff9936744 100644 (file)
@@ -99,13 +99,13 @@ func newTransferWriter(r interface{}) (t *transferWriter, err error) {
                t.TransferEncoding = rr.TransferEncoding
                t.Header = rr.Header
                t.Trailer = rr.Trailer
-               atLeastHTTP11 = rr.protoAtLeastOutgoing(1, 1)
                t.Body = rr.Body
                t.BodyCloser = rr.Body
                t.ContentLength = rr.outgoingLength()
-               if t.ContentLength < 0 && len(t.TransferEncoding) == 0 && atLeastHTTP11 && t.shouldSendChunkedRequestBody() {
+               if t.ContentLength < 0 && len(t.TransferEncoding) == 0 && t.shouldSendChunkedRequestBody() {
                        t.TransferEncoding = []string{"chunked"}
                }
+               atLeastHTTP11 = true // Transport requests are always 1.1 or 2.0
        case *Response:
                t.IsResponse = true
                if rr.Request != nil {