forked from toolshed/abra
.gitea
cli
cmd
pkg
scripts
tests
vendor
coopcloud.tech
dario.cat
git.coopcloud.tech
github.com
go.opentelemetry.io
golang.org
x
crypto
exp
net
context
http
http2
hpack
.gitignore
ascii.go
ciphers.go
client_conn_pool.go
config.go
config_go124.go
config_pre_go124.go
databuffer.go
errors.go
flow.go
frame.go
gotrack.go
headermap.go
http2.go
pipe.go
server.go
timer.go
transport.go
unencrypted.go
write.go
writesched.go
writesched_priority.go
writesched_random.go
writesched_roundrobin.go
idna
internal
proxy
trace
LICENSE
PATENTS
sync
sys
term
text
time
google.golang.org
gopkg.in
gotest.tools
modules.txt
.dockerignore
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
146 lines
4.5 KiB
Go
146 lines
4.5 KiB
Go
// 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 http2
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// An ErrCode is an unsigned 32-bit error code as defined in the HTTP/2 spec.
|
|
type ErrCode uint32
|
|
|
|
const (
|
|
ErrCodeNo ErrCode = 0x0
|
|
ErrCodeProtocol ErrCode = 0x1
|
|
ErrCodeInternal ErrCode = 0x2
|
|
ErrCodeFlowControl ErrCode = 0x3
|
|
ErrCodeSettingsTimeout ErrCode = 0x4
|
|
ErrCodeStreamClosed ErrCode = 0x5
|
|
ErrCodeFrameSize ErrCode = 0x6
|
|
ErrCodeRefusedStream ErrCode = 0x7
|
|
ErrCodeCancel ErrCode = 0x8
|
|
ErrCodeCompression ErrCode = 0x9
|
|
ErrCodeConnect ErrCode = 0xa
|
|
ErrCodeEnhanceYourCalm ErrCode = 0xb
|
|
ErrCodeInadequateSecurity ErrCode = 0xc
|
|
ErrCodeHTTP11Required ErrCode = 0xd
|
|
)
|
|
|
|
var errCodeName = map[ErrCode]string{
|
|
ErrCodeNo: "NO_ERROR",
|
|
ErrCodeProtocol: "PROTOCOL_ERROR",
|
|
ErrCodeInternal: "INTERNAL_ERROR",
|
|
ErrCodeFlowControl: "FLOW_CONTROL_ERROR",
|
|
ErrCodeSettingsTimeout: "SETTINGS_TIMEOUT",
|
|
ErrCodeStreamClosed: "STREAM_CLOSED",
|
|
ErrCodeFrameSize: "FRAME_SIZE_ERROR",
|
|
ErrCodeRefusedStream: "REFUSED_STREAM",
|
|
ErrCodeCancel: "CANCEL",
|
|
ErrCodeCompression: "COMPRESSION_ERROR",
|
|
ErrCodeConnect: "CONNECT_ERROR",
|
|
ErrCodeEnhanceYourCalm: "ENHANCE_YOUR_CALM",
|
|
ErrCodeInadequateSecurity: "INADEQUATE_SECURITY",
|
|
ErrCodeHTTP11Required: "HTTP_1_1_REQUIRED",
|
|
}
|
|
|
|
func (e ErrCode) String() string {
|
|
if s, ok := errCodeName[e]; ok {
|
|
return s
|
|
}
|
|
return fmt.Sprintf("unknown error code 0x%x", uint32(e))
|
|
}
|
|
|
|
func (e ErrCode) stringToken() string {
|
|
if s, ok := errCodeName[e]; ok {
|
|
return s
|
|
}
|
|
return fmt.Sprintf("ERR_UNKNOWN_%d", uint32(e))
|
|
}
|
|
|
|
// ConnectionError is an error that results in the termination of the
|
|
// entire connection.
|
|
type ConnectionError ErrCode
|
|
|
|
func (e ConnectionError) Error() string { return fmt.Sprintf("connection error: %s", ErrCode(e)) }
|
|
|
|
// StreamError is an error that only affects one stream within an
|
|
// HTTP/2 connection.
|
|
type StreamError struct {
|
|
StreamID uint32
|
|
Code ErrCode
|
|
Cause error // optional additional detail
|
|
}
|
|
|
|
// errFromPeer is a sentinel error value for StreamError.Cause to
|
|
// indicate that the StreamError was sent from the peer over the wire
|
|
// and wasn't locally generated in the Transport.
|
|
var errFromPeer = errors.New("received from peer")
|
|
|
|
func streamError(id uint32, code ErrCode) StreamError {
|
|
return StreamError{StreamID: id, Code: code}
|
|
}
|
|
|
|
func (e StreamError) Error() string {
|
|
if e.Cause != nil {
|
|
return fmt.Sprintf("stream error: stream ID %d; %v; %v", e.StreamID, e.Code, e.Cause)
|
|
}
|
|
return fmt.Sprintf("stream error: stream ID %d; %v", e.StreamID, e.Code)
|
|
}
|
|
|
|
// 6.9.1 The Flow Control Window
|
|
// "If a sender receives a WINDOW_UPDATE that causes a flow control
|
|
// window to exceed this maximum it MUST terminate either the stream
|
|
// or the connection, as appropriate. For streams, [...]; for the
|
|
// connection, a GOAWAY frame with a FLOW_CONTROL_ERROR code."
|
|
type goAwayFlowError struct{}
|
|
|
|
func (goAwayFlowError) Error() string { return "connection exceeded flow control window size" }
|
|
|
|
// connError represents an HTTP/2 ConnectionError error code, along
|
|
// with a string (for debugging) explaining why.
|
|
//
|
|
// Errors of this type are only returned by the frame parser functions
|
|
// and converted into ConnectionError(Code), after stashing away
|
|
// the Reason into the Framer's errDetail field, accessible via
|
|
// the (*Framer).ErrorDetail method.
|
|
type connError struct {
|
|
Code ErrCode // the ConnectionError error code
|
|
Reason string // additional reason
|
|
}
|
|
|
|
func (e connError) Error() string {
|
|
return fmt.Sprintf("http2: connection error: %v: %v", e.Code, e.Reason)
|
|
}
|
|
|
|
type pseudoHeaderError string
|
|
|
|
func (e pseudoHeaderError) Error() string {
|
|
return fmt.Sprintf("invalid pseudo-header %q", string(e))
|
|
}
|
|
|
|
type duplicatePseudoHeaderError string
|
|
|
|
func (e duplicatePseudoHeaderError) Error() string {
|
|
return fmt.Sprintf("duplicate pseudo-header %q", string(e))
|
|
}
|
|
|
|
type headerFieldNameError string
|
|
|
|
func (e headerFieldNameError) Error() string {
|
|
return fmt.Sprintf("invalid header field name %q", string(e))
|
|
}
|
|
|
|
type headerFieldValueError string
|
|
|
|
func (e headerFieldValueError) Error() string {
|
|
return fmt.Sprintf("invalid header field value for %q", string(e))
|
|
}
|
|
|
|
var (
|
|
errMixPseudoHeaderTypes = errors.New("mix of request and response pseudo headers")
|
|
errPseudoAfterRegular = errors.New("pseudo header field after regular")
|
|
)
|