|
1 From 3b6f4b04ba4da9e90e1f28dcd19c0eac78c57170 Mon Sep 17 00:00:00 2001 |
|
2 From: Chris Broadfoot <[email protected]> |
|
3 Date: Tue, 18 Oct 2016 12:52:26 -0700 |
|
4 Subject: [PATCH 28/38] [release-branch.go1.7] net/http: update bundled http2 |
|
5 |
|
6 Updates bundled http2 for x/net/http2 git rev d4c55e66 for: |
|
7 |
|
8 [release-branch.go1.7] http2: never Read from Request.Body in Transport |
|
9 to determine ContentLength |
|
10 https://golang.org/cl/31361 |
|
11 |
|
12 Updates #17480 |
|
13 Updates #17071 |
|
14 |
|
15 Change-Id: I2231adaed3cb5b368927a9654dcf7e69a8b664b6 |
|
16 Reviewed-on: https://go-review.googlesource.com/31432 |
|
17 Run-TryBot: Chris Broadfoot <[email protected]> |
|
18 TryBot-Result: Gobot Gobot <[email protected]> |
|
19 Reviewed-by: Chris Broadfoot <[email protected]> |
|
20 --- |
|
21 src/net/http/h2_bundle.go | 33 ++++++++++----------------------- |
|
22 1 file changed, 10 insertions(+), 23 deletions(-) |
|
23 |
|
24 diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go |
|
25 index 80c02d0..063043a 100644 |
|
26 --- a/src/net/http/h2_bundle.go |
|
27 +++ b/src/net/http/h2_bundle.go |
|
28 @@ -5448,31 +5448,17 @@ func http2checkConnHeaders(req *Request) error { |
|
29 return nil |
|
30 } |
|
31 |
|
32 -func http2bodyAndLength(req *Request) (body io.Reader, contentLen int64) { |
|
33 - body = req.Body |
|
34 - if body == nil { |
|
35 - return nil, 0 |
|
36 +// actualContentLength returns a sanitized version of |
|
37 +// req.ContentLength, where 0 actually means zero (not unknown) and -1 |
|
38 +// means unknown. |
|
39 +func http2actualContentLength(req *Request) int64 { |
|
40 + if req.Body == nil { |
|
41 + return 0 |
|
42 } |
|
43 if req.ContentLength != 0 { |
|
44 - return req.Body, req.ContentLength |
|
45 - } |
|
46 - |
|
47 - // We have a body but a zero content length. Test to see if |
|
48 - // it's actually zero or just unset. |
|
49 - var buf [1]byte |
|
50 - n, rerr := body.Read(buf[:]) |
|
51 - if rerr != nil && rerr != io.EOF { |
|
52 - return http2errorReader{rerr}, -1 |
|
53 + return req.ContentLength |
|
54 } |
|
55 - if n == 1 { |
|
56 - |
|
57 - if rerr == io.EOF { |
|
58 - return bytes.NewReader(buf[:]), 1 |
|
59 - } |
|
60 - return io.MultiReader(bytes.NewReader(buf[:]), body), -1 |
|
61 - } |
|
62 - |
|
63 - return nil, 0 |
|
64 + return -1 |
|
65 } |
|
66 |
|
67 func (cc *http2ClientConn) RoundTrip(req *Request) (*Response, error) { |
|
68 @@ -5493,8 +5479,9 @@ func (cc *http2ClientConn) RoundTrip(req *Request) (*Response, error) { |
|
69 return nil, http2errClientConnUnusable |
|
70 } |
|
71 |
|
72 - body, contentLen := http2bodyAndLength(req) |
|
73 + body := req.Body |
|
74 hasBody := body != nil |
|
75 + contentLen := http2actualContentLength(req) |
|
76 |
|
77 // TODO(bradfitz): this is a copy of the logic in net/http. Unify somewhere? |
|
78 var requestedGzip bool |
|
79 -- |
|
80 2.7.4 |
|
81 |