// 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.package http2import ()var (VerboseLogsbool logFrameWrites bool logFrameReads bool inTests bool)func init() { := os.Getenv("GODEBUG")ifstrings.Contains(, "http2debug=1") {VerboseLogs = true }ifstrings.Contains(, "http2debug=2") {VerboseLogs = truelogFrameWrites = truelogFrameReads = true }}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"// NextProtoTLS is the NPN/ALPN protocol negotiated during // HTTP/2's TLS setup.NextProtoTLS = "h2"// https://httpwg.org/specs/rfc7540.html#SettingValues initialHeaderTableSize = 4096 initialWindowSize = 65535// 6.9.2 Initial Flow Control Window Size)var clientPreface = []byte(ClientPreface)// validWireHeaderFieldName reports whether v is a valid header field// name (key). See httpguts.ValidHeaderName for the base rules.//// Further, http2 says://// "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. "func validWireHeaderFieldName( string) bool {iflen() == 0 {returnfalse }for , := range {if !httpguts.IsTokenRune() {returnfalse }if'A' <= && <= 'Z' {returnfalse } }returntrue}func httpCodeString( int) string {switch {case200:return"200"case404:return"404" }returnstrconv.Itoa()}// bufWriterPoolBufferSize is the size of bufio.Writer's// buffers created using bufWriterPool.//// TODO: pick a less arbitrary value? this is a bit under// (3 x typical 1500 byte MTU) at least. Other than that,// not much thought went into it.const bufWriterPoolBufferSize = 4 << 10var bufWriterPool = sync.Pool{New: func() any {returnbufio.NewWriterSize(nil, bufWriterPoolBufferSize) },}func mustUint31( int32) uint32 {if < 0 || > 2147483647 {panic("out of range") }returnuint32()}// bodyAllowedForStatus reports whether a given response status code// permits a body. See RFC 7230, section 3.3.func bodyAllowedForStatus( int) bool {switch {case >= 100 && <= 199:returnfalsecase == 204:returnfalsecase == 304:returnfalse }returntrue}type httpError struct { _ incomparable msg string timeout bool}func ( *httpError) () string { return .msg }func ( *httpError) () bool { return .timeout }func ( *httpError) () bool { returntrue }var errH2Timeout error = &httpError{msg: "http2: timeout awaiting response headers", timeout: true}type connectionStater interface { ConnectionState() tls.ConnectionState}var sorterPool = sync.Pool{New: func() any { returnnew(sorter) }}type sorter struct { v []string// owned by sorter}func ( *sorter) () int { returnlen(.v) }func ( *sorter) (, int) { .v[], .v[] = .v[], .v[] }func ( *sorter) (, int) bool { return .v[] < .v[] }// Keys returns the sorted keys of h.//// The returned slice is only valid until s used again or returned to// its pool.func ( *sorter) ( http.Header) []string { := .v[:0]for := range { = append(, ) } .v = sort.Sort()return}func ( *sorter) ( []string) {// Our sorter works on s.v, which sorter owns, so // stash it away while we sort the user's buffer. := .v .v = sort.Sort() .v = }// validPseudoPath reports whether v is a valid :path pseudo-header// value. It must be either://// *) a non-empty string starting with '/'// *) the string '*', for OPTIONS requests.//// For now this is only used a quick check for deciding when to clean// up Opaque URLs before sending requests from the Transport.// See golang.org/issue/16847//// We used to enforce that the path also didn't start with "//", but// Google's GFE accepts such paths and Chrome sends them, so ignore// that part of the spec. See golang.org/issue/19103.func validPseudoPath( string) bool {return (len() > 0 && [0] == '/') || == "*"}// incomparable is a zero-width, non-comparable type. Adding it to a struct// makes that struct also non-comparable, and generally doesn't add// any size (as long as it's first).type incomparable [0]func()
The pages are generated with Goldsv0.8.7. (GOOS=linux 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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds.