forked from summerwind/h2spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_5.go
54 lines (46 loc) · 1.07 KB
/
3_5.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"
"io"
"net"
"syscall"
"time"
)
func Http2ConnectionPrefaceTestGroup(ctx *Context) *TestGroup {
tg := NewTestGroup("3.5", "HTTP/2 Connection Preface")
tg.AddTestCase(NewTestCase(
"Sends invalid connection preface",
"The endpoint MUST terminate the TCP connection.",
func(ctx *Context) (pass bool, expected []Result, actual Result) {
pass = false
expected = []Result{
&ResultConnectionClose{},
}
tcpConn := CreateTcpConn(ctx)
defer tcpConn.conn.Close()
fmt.Fprintf(tcpConn.conn, "INVALID CONNECTION PREFACE\r\n\r\n")
timeCh := time.After(ctx.Timeout)
loop:
for {
select {
case <-tcpConn.dataCh:
break
case err := <-tcpConn.errCh:
opErr, ok := err.(*net.OpError)
if err == io.EOF || (ok && opErr.Err == syscall.ECONNRESET) {
pass = true
actual = &ResultConnectionClose{}
} else {
actual = &ResultError{err}
}
break loop
case <-timeCh:
actual = &ResultTestTimeout{}
break loop
}
}
return pass, expected, actual
},
))
return tg
}