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