/
1_starting_http2.go
53 lines (43 loc) · 1.16 KB
/
1_starting_http2.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
package generic
import (
"github.com/summerwind/h2spec/config"
"github.com/summerwind/h2spec/spec"
"golang.org/x/net/http2"
)
func StartingHTTP2() *spec.TestGroup {
tg := NewTestGroup("1", "Starting HTTP/2")
// RFC7540, 3.2:
// The first HTTP/2 frame sent by the server MUST be a server connection
// preface (Section 3.5) consisting of a SETTINGS frame (Section 6.5).
tg.AddTestCase(&spec.TestCase{
Desc: "Sends a client connection preface",
Requirement: "The endpoint MUST accept client connection preface.",
Run: func(c *config.Config, conn *spec.Conn) error {
var passed bool
setting := http2.Setting{
ID: http2.SettingInitialWindowSize,
Val: spec.DefaultWindowSize,
}
conn.Send([]byte("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"))
conn.WriteSettings(setting)
actual := conn.WaitEvent()
switch event := actual.(type) {
case spec.SettingsFrameEvent:
passed = !event.IsAck()
default:
passed = false
}
if !passed {
expected := []string{
"SETTINGS Frame (flags:0x00)",
}
return &spec.TestError{
Expected: expected,
Actual: actual.String(),
}
}
return nil
},
})
return tg
}