| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- // 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
- )
- 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)
- }
|