Source File
http2.go
Belonging Package
golang.org/x/net/http2
package http2 // import "golang.org/x/net/http2"
import (
)
var (
VerboseLogs bool
logFrameWrites bool
logFrameReads bool
inTests bool
)
func () {
:= os.Getenv("GODEBUG")
if strings.Contains(, "http2debug=1") {
VerboseLogs = true
}
if strings.Contains(, "http2debug=2") {
VerboseLogs = true
logFrameWrites = true
logFrameReads = true
}
}
ClientPreface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
initialMaxFrameSize = 16384
NextProtoTLS = "h2"
initialHeaderTableSize = 4096
initialWindowSize = 65535 // 6.9.2 Initial Flow Control Window Size
defaultMaxReadFrameSize = 1 << 20
)
var (
clientPreface = []byte(ClientPreface)
)
type streamState int
const (
stateIdle streamState = iota
stateOpen
stateHalfClosedLocal
stateHalfClosedRemote
stateClosed
)
var stateName = [...]string{
stateIdle: "Idle",
stateOpen: "Open",
stateHalfClosedLocal: "HalfClosedLocal",
stateHalfClosedRemote: "HalfClosedRemote",
stateClosed: "Closed",
}
func ( streamState) () string {
return stateName[]
}
switch .ID {
case SettingEnablePush:
if .Val != 1 && .Val != 0 {
return ConnectionError(ErrCodeProtocol)
}
case SettingInitialWindowSize:
if .Val > 1<<31-1 {
return ConnectionError(ErrCodeFlowControl)
}
case SettingMaxFrameSize:
if .Val < 16384 || .Val > 1<<24-1 {
return ConnectionError(ErrCodeProtocol)
}
}
return nil
}
type SettingID uint16
const (
SettingHeaderTableSize SettingID = 0x1
SettingEnablePush SettingID = 0x2
SettingMaxConcurrentStreams SettingID = 0x3
SettingInitialWindowSize SettingID = 0x4
SettingMaxFrameSize SettingID = 0x5
SettingMaxHeaderListSize SettingID = 0x6
)
var settingName = map[SettingID]string{
SettingHeaderTableSize: "HEADER_TABLE_SIZE",
SettingEnablePush: "ENABLE_PUSH",
SettingMaxConcurrentStreams: "MAX_CONCURRENT_STREAMS",
SettingInitialWindowSize: "INITIAL_WINDOW_SIZE",
SettingMaxFrameSize: "MAX_FRAME_SIZE",
SettingMaxHeaderListSize: "MAX_HEADER_LIST_SIZE",
}
func ( SettingID) () string {
if , := settingName[]; {
return
}
return fmt.Sprintf("UNKNOWN_SETTING_%d", uint16())
}
type stringWriter interface {
WriteString(s string) (n int, err error)
}
type closeWaiter chan struct{}
func ( *closeWaiter) () {
* = make(chan struct{})
}
func ( closeWaiter) () {
close()
}
func ( closeWaiter) () {
<-
}
type bufferedWriter struct {
_ incomparable
w io.Writer // immutable
bw *bufio.Writer // non-nil when data is buffered
}
func ( io.Writer) *bufferedWriter {
return &bufferedWriter{w: }
}
const bufWriterPoolBufferSize = 4 << 10
var bufWriterPool = sync.Pool{
New: func() interface{} {
return bufio.NewWriterSize(nil, bufWriterPoolBufferSize)
},
}
func ( *bufferedWriter) () int {
if .bw == nil {
return bufWriterPoolBufferSize
}
return .bw.Available()
}
func ( *bufferedWriter) ( []byte) ( int, error) {
if .bw == nil {
:= bufWriterPool.Get().(*bufio.Writer)
.Reset(.w)
.bw =
}
return .bw.Write()
}
func ( *bufferedWriter) () error {
:= .bw
if == nil {
return nil
}
:= .Flush()
.Reset(nil)
bufWriterPool.Put()
.bw = nil
return
}
func ( int32) uint32 {
if < 0 || > 2147483647 {
panic("out of range")
}
return uint32()
}
func ( int) bool {
switch {
case >= 100 && <= 199:
return false
case == 204:
return false
case == 304:
return false
}
return true
}
type httpError struct {
_ incomparable
msg string
timeout bool
}
func ( *httpError) () string { return .msg }
func ( *httpError) () bool { return .timeout }
func ( *httpError) () bool { return true }
var errTimeout error = &httpError{msg: "http2: timeout awaiting response headers", timeout: true}
type connectionStater interface {
ConnectionState() tls.ConnectionState
}
var sorterPool = sync.Pool{New: func() interface{} { return new(sorter) }}
type sorter struct {
v []string // owned by sorter
}
func ( *sorter) () int { return len(.v) }
func ( *sorter) (, int) { .v[], .v[] = .v[], .v[] }
func ( *sorter) (, int) bool { return .v[] < .v[] }
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |