/
h2.go
50 lines (42 loc) · 1.07 KB
/
h2.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
package h2
import (
"io"
"golang.org/x/net/http2"
"golang.org/x/net/http2/hpack"
)
type State int
const (
connected State = iota
closing
closed
)
const (
defaultMaxHeaderListSize = uint32(16 << 20)
defaultMaxFramSize = uint32(16384)
defaultHeaderTableSize = uint32(4096)
defaultWindowSize = uint32(65535)
defaultConnWindowSize = uint32(65535)
)
// ConnectOptions options for http2 connect with the server.
type ConnectOptions struct {
InitialWindowSize uint32
InitialConnWindowSize uint32
MaxFrameSize uint32
MaxHeaderListSize *uint32
MaxConcurrentStreams uint32
InitialMaxSendStreams uint32
MaxConcurrentResetStreams uint32
EnablePush bool
}
type framer struct {
fr *http2.Framer
}
func newFramer(conn io.ReadWriteCloser, maxFramSize, maxHeaderListSize uint32) *framer {
f := &framer{
fr: http2.NewFramer(conn, conn),
}
f.fr.SetMaxReadFrameSize(maxFramSize)
f.fr.MaxHeaderListSize = maxHeaderListSize
f.fr.ReadMetaHeaders = hpack.NewDecoder(defaultHeaderTableSize, nil)
return f
}