/
3_1_data.go
113 lines (91 loc) · 2.85 KB
/
3_1_data.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
110
111
112
113
package generic
import (
"golang.org/x/net/http2"
"github.com/summerwind/h2spec/config"
"github.com/summerwind/h2spec/spec"
)
func Data() *spec.TestGroup {
tg := NewTestGroup("3.1", "DATA")
// RFC7540, 6.1:
// DATA frames (type=0x0) convey arbitrary, variable-length
// sequences of octets associated with a stream. One or more
// DATA frames are used, for instance, to carry HTTP request
// or response payloads.
tg.AddTestCase(&spec.TestCase{
Desc: "Sends a DATA frame",
Requirement: "The endpoint MUST accept DATA 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)
headers[0].Value = "POST"
hp := http2.HeadersFrameParam{
StreamID: streamID,
EndStream: false,
EndHeaders: true,
BlockFragment: conn.EncodeHeaders(headers),
}
conn.WriteHeaders(hp)
conn.WriteData(streamID, true, []byte("test"))
return spec.VerifyHeadersFrame(conn, streamID)
},
})
// RFC7540, 6.1:
// DATA frames (type=0x0) convey arbitrary, variable-length
// sequences of octets associated with a stream. One or more
// DATA frames are used, for instance, to carry HTTP request
// or response payloads.
tg.AddTestCase(&spec.TestCase{
Desc: "Sends multiple DATA frames",
Requirement: "The endpoint MUST accept multiple DATA frames.",
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)
headers[0].Value = "POST"
hp := http2.HeadersFrameParam{
StreamID: streamID,
EndStream: false,
EndHeaders: true,
BlockFragment: conn.EncodeHeaders(headers),
}
conn.WriteHeaders(hp)
conn.WriteData(streamID, false, []byte("test"))
conn.WriteData(streamID, true, []byte("test"))
return spec.VerifyHeadersFrame(conn, streamID)
},
})
// RFC7540, 6.1:
// DATA frames MAY also contain padding. Padding can be added to
// DATA frames to obscure the size of messages. Padding is a
// security feature; see Section 10.7.
tg.AddTestCase(&spec.TestCase{
Desc: "Sends a DATA frame with padding",
Requirement: "The endpoint MUST accept DATA 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)
headers[0].Value = "POST"
hp := http2.HeadersFrameParam{
StreamID: streamID,
EndStream: false,
EndHeaders: true,
BlockFragment: conn.EncodeHeaders(headers),
}
conn.WriteHeaders(hp)
conn.WriteDataPadded(streamID, true, []byte("test"), []byte("\x00\x00\x00\x00\x00"))
return spec.VerifyHeadersFrame(conn, streamID)
},
})
return tg
}