| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- // Copyright 2014 The Go Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license that can be found in the LICENSE file.
- // See https://code.google.com/p/go/source/browse/CONTRIBUTORS
- // Licensed under the same terms as Go itself:
- // https://code.google.com/p/go/source/browse/LICENSE
- // Package http2 implements the HTTP/2 protocol.
- //
- // This is a work in progress. This package is low-level and intended
- // to be used directly by very few people. Most users will use it
- // indirectly through integration with the net/http package. See
- // ConfigureServer. That ConfigureServer call will likely be automatic
- // or available via an empty import in the future.
- //
- // This package currently targets draft-14. See http://http2.github.io/
- package http2
- import (
- "net/http"
- "strconv"
- )
- var VerboseLogs = false
- const (
- // ClientPreface is the string that must be sent by new
- // connections from clients.
- ClientPreface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
- // SETTINGS_MAX_FRAME_SIZE default
- // http://http2.github.io/http2-spec/#rfc.section.6.5.2
- initialMaxFrameSize = 16384
- npnProto = "h2-14"
- // http://http2.github.io/http2-spec/#SettingValues
- initialHeaderTableSize = 4096
- initialWindowSize = 65535 // 6.9.2 Initial Flow Control Window Size
- )
- var (
- clientPreface = []byte(ClientPreface)
- )
- type streamState int
- const (
- stateIdle streamState = iota
- stateOpen
- stateHalfClosedLocal
- stateHalfClosedRemote
- stateResvLocal
- stateResvRemote
- stateClosed
- )
- var stateName = [...]string{
- stateIdle: "Idle",
- stateOpen: "Open",
- stateHalfClosedLocal: "HalfClosedLocal",
- stateHalfClosedRemote: "HalfClosedRemote",
- stateResvLocal: "ResvLocal",
- stateResvRemote: "ResvRemote",
- stateClosed: "Closed",
- }
- func (st streamState) String() string {
- return stateName[st]
- }
- func validHeader(v string) bool {
- if len(v) == 0 {
- return false
- }
- for _, r := range v {
- // "Just as in HTTP/1.x, header field names are
- // strings of ASCII characters that are compared in a
- // case-insensitive fashion. However, header field
- // names MUST be converted to lowercase prior to their
- // encoding in HTTP/2. "
- if r >= 127 || ('A' <= r && r <= 'Z') {
- return false
- }
- }
- return true
- }
- var httpCodeStringCommon = map[int]string{} // n -> strconv.Itoa(n)
- func init() {
- for i := 100; i <= 999; i++ {
- if v := http.StatusText(i); v != "" {
- httpCodeStringCommon[i] = strconv.Itoa(i)
- }
- }
- }
- func httpCodeString(code int) string {
- if s, ok := httpCodeStringCommon[code]; ok {
- return s
- }
- return strconv.Itoa(code)
- }
- // from pkg io
- type stringWriter interface {
- WriteString(s string) (n int, err error)
- }
- // A gate lets two goroutines coordinate their activities.
- type gate chan struct{}
- func (g gate) Done() { g <- struct{}{} }
- func (g gate) Wait() { <-g }
|