forked from summerwind/h2spec
/
8_1_http_request_response_exchange.go
61 lines (48 loc) · 1.52 KB
/
8_1_http_request_response_exchange.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
package http2
import (
"github.com/summerwind/h2spec/config"
"github.com/summerwind/h2spec/spec"
"golang.org/x/net/http2"
"golang.org/x/net/http2/hpack"
)
func HTTPRequestResponseExchange() *spec.TestGroup {
tg := NewTestGroup("8.1", "HTTP Request/Response Exchange")
// An endpoint that receives a HEADERS frame without the
// END_STREAM flag set after receiving a final (non-informational)
// status code MUST treat the corresponding request or response
// as malformed (Section 8.1.2.6).
tg.AddTestCase(&spec.TestCase{
Desc: "Sends a second HEADERS frame without the END_STREAM flag",
Requirement: "The endpoint MUST respond with a stream error of type PROTOCOL_ERROR.",
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"
hp1 := http2.HeadersFrameParam{
StreamID: streamID,
EndStream: false,
EndHeaders: true,
BlockFragment: conn.EncodeHeaders(headers),
}
conn.WriteHeaders(hp1)
conn.WriteData(streamID, false, []byte("test"))
trailers := []hpack.HeaderField{
spec.HeaderField("x-test", "ok"),
}
hp2 := http2.HeadersFrameParam{
StreamID: streamID,
EndStream: false,
EndHeaders: true,
BlockFragment: conn.EncodeHeaders(trailers),
}
conn.WriteHeaders(hp2)
return spec.VerifyStreamError(conn, http2.ErrCodeProtocol)
},
})
tg.AddTestGroup(HTTPHeaderFields())
return tg
}