-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathconfig_test.go
95 lines (85 loc) · 2.79 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2024 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.
//go:build go1.24
package http2
import (
"net/http"
"testing"
"time"
)
func TestConfigServerSettings(t *testing.T) {
config := &http.HTTP2Config{
MaxConcurrentStreams: 1,
MaxDecoderHeaderTableSize: 1<<20 + 2,
MaxEncoderHeaderTableSize: 1<<20 + 3,
MaxReadFrameSize: 1<<20 + 4,
MaxReceiveBufferPerConnection: 64<<10 + 5,
MaxReceiveBufferPerStream: 64<<10 + 6,
}
const maxHeaderBytes = 4096 + 7
st := newServerTester(t, nil, func(s *http.Server) {
s.MaxHeaderBytes = maxHeaderBytes
s.HTTP2 = config
})
st.writePreface()
st.writeSettings()
st.wantSettings(map[SettingID]uint32{
SettingMaxConcurrentStreams: uint32(config.MaxConcurrentStreams),
SettingHeaderTableSize: uint32(config.MaxDecoderHeaderTableSize),
SettingInitialWindowSize: uint32(config.MaxReceiveBufferPerStream),
SettingMaxFrameSize: uint32(config.MaxReadFrameSize),
SettingMaxHeaderListSize: maxHeaderBytes + (32 * 10),
})
}
func TestConfigTransportSettings(t *testing.T) {
config := &http.HTTP2Config{
MaxConcurrentStreams: 1, // ignored by Transport
MaxDecoderHeaderTableSize: 1<<20 + 2,
MaxEncoderHeaderTableSize: 1<<20 + 3,
MaxReadFrameSize: 1<<20 + 4,
MaxReceiveBufferPerConnection: 64<<10 + 5,
MaxReceiveBufferPerStream: 64<<10 + 6,
}
const maxHeaderBytes = 4096 + 7
tc := newTestClientConn(t, func(tr *http.Transport) {
tr.HTTP2 = config
tr.MaxResponseHeaderBytes = maxHeaderBytes
})
tc.wantSettings(map[SettingID]uint32{
SettingHeaderTableSize: uint32(config.MaxDecoderHeaderTableSize),
SettingInitialWindowSize: uint32(config.MaxReceiveBufferPerStream),
SettingMaxFrameSize: uint32(config.MaxReadFrameSize),
SettingMaxHeaderListSize: maxHeaderBytes + (32 * 10),
})
tc.wantWindowUpdate(0, uint32(config.MaxReceiveBufferPerConnection))
}
func TestConfigPingTimeoutServer(t *testing.T) {
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
}, func(s *Server) {
s.ReadIdleTimeout = 2 * time.Second
s.PingTimeout = 3 * time.Second
})
st.greet()
st.advance(2 * time.Second)
_ = readFrame[*PingFrame](t, st)
st.advance(3 * time.Second)
st.wantClosed()
}
func TestConfigPingTimeoutTransport(t *testing.T) {
tc := newTestClientConn(t, func(tr *Transport) {
tr.ReadIdleTimeout = 2 * time.Second
tr.PingTimeout = 3 * time.Second
})
tc.greet()
req, _ := http.NewRequest("GET", "https://dummy.tld/", nil)
rt := tc.roundTrip(req)
tc.wantFrameType(FrameHeaders)
tc.advance(2 * time.Second)
tc.wantFrameType(FramePing)
tc.advance(3 * time.Second)
err := rt.err()
if err == nil {
t.Fatalf("expected connection to close")
}
}