forked from summerwind/h2spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_4.go
54 lines (45 loc) · 1.11 KB
/
5_4.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
package h2spec
import (
"fmt"
"github.com/bradfitz/http2"
"io"
)
func TestErrorHandling(ctx *Context) {
if !ctx.IsTarget("5.4") {
return
}
PrintHeader("5.4. Error Handling", 0)
TestConnectionErrorHandling(ctx)
PrintFooter()
}
func TestConnectionErrorHandling(ctx *Context) {
PrintHeader("5.4.1. Connection Error Handling", 1)
func(ctx *Context) {
desc := "Receives a GOAWAY frame"
msg := "After sending the GOAWAY frame, the endpoint MUST close the TCP connection."
gfResult := false
closeResult := false
http2Conn := CreateHttp2Conn(ctx, true)
defer http2Conn.conn.Close()
// PING frame with invalid stream ID
fmt.Fprintf(http2Conn.conn, "\x00\x00\x08\x06\x00\x00\x00\x00\x03")
fmt.Fprintf(http2Conn.conn, "\x00\x00\x00\x00\x00\x00\x00\x00")
loop:
for {
f, err := http2Conn.ReadFrame(ctx.Timeout)
if err != nil {
if err == io.EOF {
closeResult = true
}
break loop
}
switch f := f.(type) {
case *http2.GoAwayFrame:
if f.ErrCode == http2.ErrCodeProtocol {
gfResult = true
}
}
}
PrintResult(gfResult && closeResult, desc, msg, 1)
}(ctx)
}