Skip to content

Commit c40a73d

Browse files
committed
net/http: make hidden http2 Transport respect remaining Transport fields
Updates x/net/http2 to git rev 72aa00c6 for https://golang.org/cl/18721 (but actually at https://golang.org/cl/18722 now) Fixes #14008 Change-Id: If05d5ad51ec0ba5ba7e4fe16605c0a83f0484bc8 Reviewed-on: https://go-review.googlesource.com/18723 Run-TryBot: Brad Fitzpatrick <[email protected]> Reviewed-by: Andrew Gerrand <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 3208d92 commit c40a73d

File tree

2 files changed

+155
-39
lines changed

2 files changed

+155
-39
lines changed

src/net/http/clientserver_test.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,24 @@ const (
4747
h2Mode = true
4848
)
4949

50-
func newClientServerTest(t *testing.T, h2 bool, h Handler) *clientServerTest {
50+
func newClientServerTest(t *testing.T, h2 bool, h Handler, opts ...interface{}) *clientServerTest {
5151
cst := &clientServerTest{
5252
t: t,
5353
h2: h2,
5454
h: h,
5555
tr: &Transport{},
5656
}
5757
cst.c = &Client{Transport: cst.tr}
58+
59+
for _, opt := range opts {
60+
switch opt := opt.(type) {
61+
case func(*Transport):
62+
opt(cst.tr)
63+
default:
64+
t.Fatalf("unhandled option type %T", opt)
65+
}
66+
}
67+
5868
if !h2 {
5969
cst.ts = httptest.NewServer(h)
6070
return cst
@@ -139,6 +149,7 @@ type h12Compare struct {
139149
Handler func(ResponseWriter, *Request) // required
140150
ReqFunc reqFunc // optional
141151
CheckResponse func(proto string, res *Response) // optional
152+
Opts []interface{}
142153
}
143154

144155
func (tt h12Compare) reqFunc() reqFunc {
@@ -149,9 +160,9 @@ func (tt h12Compare) reqFunc() reqFunc {
149160
}
150161

151162
func (tt h12Compare) run(t *testing.T) {
152-
cst1 := newClientServerTest(t, false, HandlerFunc(tt.Handler))
163+
cst1 := newClientServerTest(t, false, HandlerFunc(tt.Handler), tt.Opts...)
153164
defer cst1.close()
154-
cst2 := newClientServerTest(t, true, HandlerFunc(tt.Handler))
165+
cst2 := newClientServerTest(t, true, HandlerFunc(tt.Handler), tt.Opts...)
155166
defer cst2.close()
156167

157168
res1, err := tt.reqFunc()(cst1.c, cst1.ts.URL)
@@ -380,6 +391,20 @@ func TestH12_AutoGzip(t *testing.T) {
380391
}.run(t)
381392
}
382393

394+
func TestH12_AutoGzip_Disabled(t *testing.T) {
395+
h12Compare{
396+
Opts: []interface{}{
397+
func(tr *Transport) { tr.DisableCompression = true },
398+
},
399+
Handler: func(w ResponseWriter, r *Request) {
400+
fmt.Fprintf(w, "%q", r.Header["Accept-Encoding"])
401+
if ae := r.Header.Get("Accept-Encoding"); ae != "" {
402+
t.Errorf("%s Accept-Encoding = %q; want empty", r.Proto, ae)
403+
}
404+
},
405+
}.run(t)
406+
}
407+
383408
// Test304Responses verifies that 304s don't declare that they're
384409
// chunking in their response headers and aren't allowed to produce
385410
// output.

0 commit comments

Comments
 (0)