/
3_2_headers.go
109 lines (92 loc) · 2.83 KB
/
3_2_headers.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package generic
import (
"golang.org/x/net/http2"
"github.com/summerwind/h2spec/config"
"github.com/summerwind/h2spec/spec"
)
func Headers() *spec.TestGroup {
tg := NewTestGroup("3.2", "HEADERS")
// RFC7540, 6.2:
// The HEADERS frame (type=0x1) is used to open a stream
// (Section 5.1), and additionally carries a header block fragment.
tg.AddTestCase(&spec.TestCase{
Desc: "Sends a HEADERS frame",
Requirement: "The endpoint MUST accept HEADERS frame.",
Run: func(c *config.Config, conn *spec.Conn) error {
var streamID uint32 = 1
err := conn.Handshake()
if err != nil {
return err
}
headers := spec.CommonHeaders(c)
hp := http2.HeadersFrameParam{
StreamID: streamID,
EndStream: true,
EndHeaders: true,
BlockFragment: conn.EncodeHeaders(headers),
}
conn.WriteHeaders(hp)
return spec.VerifyHeadersFrame(conn, streamID)
},
})
// RFC7540, 6.2:
// The HEADERS frame can include padding. Padding fields and flags
// are identical to those defined for DATA frames (Section 6.1).
// Padding that exceeds the size remaining for the header block
// fragment MUST be treated as a PROTOCOL_ERROR.
tg.AddTestCase(&spec.TestCase{
Desc: "Sends a HEADERS frame with padding",
Requirement: "The endpoint MUST accept HEADERS frame with padding.",
Run: func(c *config.Config, conn *spec.Conn) error {
var streamID uint32 = 1
err := conn.Handshake()
if err != nil {
return err
}
headers := spec.CommonHeaders(c)
hp := http2.HeadersFrameParam{
StreamID: streamID,
EndStream: true,
EndHeaders: true,
BlockFragment: conn.EncodeHeaders(headers),
PadLength: 8,
}
conn.WriteHeaders(hp)
return spec.VerifyHeadersFrame(conn, streamID)
},
})
// RFC7540, 6.2:
// Prioritization information in a HEADERS frame is logically
// equivalent to a separate PRIORITY frame, but inclusion in
// HEADERS avoids the potential for churn in stream prioritization
// when new streams are created. Prioritization fields in HEADERS
// frames subsequent to the first on a stream reprioritize the
// stream (Section 5.3.3).
tg.AddTestCase(&spec.TestCase{
Desc: "Sends a HEADERS frame with priority",
Requirement: "The endpoint MUST accept HEADERS frame with priority.",
Run: func(c *config.Config, conn *spec.Conn) error {
var streamID uint32 = 1
err := conn.Handshake()
if err != nil {
return err
}
pp := http2.PriorityParam{
StreamDep: 0,
Exclusive: false,
Weight: 255,
}
headers := spec.CommonHeaders(c)
hp := http2.HeadersFrameParam{
StreamID: streamID,
EndStream: true,
EndHeaders: true,
BlockFragment: conn.EncodeHeaders(headers),
Priority: pp,
}
conn.WriteHeaders(hp)
return spec.VerifyHeadersFrame(conn, streamID)
},
})
return tg
}