浏览代码

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>
Brad Fitzpatrick 10 年之前
父节点
当前提交
cf147af37e
共有 4 个文件被更改,包括 28 次插入6 次删除
  1. 2 4
      http2/go15.go
  2. 11 0
      http2/not_go15.go
  3. 13 0
      http2/not_go16.go
  4. 2 2
      http2/transport.go

+ 2 - 4
http2/go15.go

@@ -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 - 0
http2/not_go15.go

@@ -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 - 0
http2/not_go16.go

@@ -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
+}

+ 2 - 2
http2/transport.go

@@ -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")