mirror of
https://github.com/golang/net.git
synced 2026-04-01 02:47:08 +09:00
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:
@@ -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
11
http2/not_go15.go
Normal 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
13
http2/not_go16.go
Normal 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
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user