http2: fix build for Go 1.4 users

Request.Cancel was added in Go 1.5.

Change-Id: Iff28824315a58956fcfcb36d9bca6228cf6ea4f6
Reviewed-on: https://go-review.googlesource.com/17822
Reviewed-by: Qi Zhao <zhaoq@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Brad Fitzpatrick
2015-12-14 22:59:31 +00:00
parent 08a7b454b0
commit cf147af37e
4 changed files with 28 additions and 6 deletions

View File

@@ -2,12 +2,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !go1.6
// +build go1.5
package http2
import "net/http"
func configureTransport(t1 *http.Transport) error {
return errTransportVersion
}
func requestCancel(req *http.Request) <-chan struct{} { return req.Cancel }

11
http2/not_go15.go Normal file
View File

@@ -0,0 +1,11 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !go1.5
package http2
import "net/http"
func requestCancel(req *http.Request) <-chan struct{} { return nil }

13
http2/not_go16.go Normal file
View File

@@ -0,0 +1,13 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !go1.6
package http2
import "net/http"
func configureTransport(t1 *http.Transport) error {
return errTransportVersion
}

View File

@@ -581,7 +581,7 @@ func (cc *ClientConn) RoundTrip(req *http.Request) (*http.Response, error) {
res.Request = req
res.TLS = cc.tlsState
return res, nil
case <-req.Cancel:
case <-requestCancel(req):
cs.abortRequestBodyWrite()
return nil, errRequestCanceled
case err := <-bodyCopyErrc:
@@ -958,7 +958,7 @@ func (rl *clientConnReadLoop) processHeaderBlockFragment(frag []byte, streamID u
cs.bufPipe = pipe{b: buf}
cs.bytesRemain = res.ContentLength
res.Body = transportResponseBody{cs}
go cs.awaitRequestCancel(cs.req.Cancel)
go cs.awaitRequestCancel(requestCancel(cs.req))
if cs.requestedGzip && res.Header.Get("Content-Encoding") == "gzip" {
res.Header.Del("Content-Encoding")