...
1
2
3
4
5 package http2
6
7 import (
8 "errors"
9 "fmt"
10 )
11
12
13 type ErrCode uint32
14
15 const (
16 ErrCodeNo ErrCode = 0x0
17 ErrCodeProtocol ErrCode = 0x1
18 ErrCodeInternal ErrCode = 0x2
19 ErrCodeFlowControl ErrCode = 0x3
20 ErrCodeSettingsTimeout ErrCode = 0x4
21 ErrCodeStreamClosed ErrCode = 0x5
22 ErrCodeFrameSize ErrCode = 0x6
23 ErrCodeRefusedStream ErrCode = 0x7
24 ErrCodeCancel ErrCode = 0x8
25 ErrCodeCompression ErrCode = 0x9
26 ErrCodeConnect ErrCode = 0xa
27 ErrCodeEnhanceYourCalm ErrCode = 0xb
28 ErrCodeInadequateSecurity ErrCode = 0xc
29 ErrCodeHTTP11Required ErrCode = 0xd
30 )
31
32 var errCodeName = map[ErrCode]string{
33 ErrCodeNo: "NO_ERROR",
34 ErrCodeProtocol: "PROTOCOL_ERROR",
35 ErrCodeInternal: "INTERNAL_ERROR",
36 ErrCodeFlowControl: "FLOW_CONTROL_ERROR",
37 ErrCodeSettingsTimeout: "SETTINGS_TIMEOUT",
38 ErrCodeStreamClosed: "STREAM_CLOSED",
39 ErrCodeFrameSize: "FRAME_SIZE_ERROR",
40 ErrCodeRefusedStream: "REFUSED_STREAM",
41 ErrCodeCancel: "CANCEL",
42 ErrCodeCompression: "COMPRESSION_ERROR",
43 ErrCodeConnect: "CONNECT_ERROR",
44 ErrCodeEnhanceYourCalm: "ENHANCE_YOUR_CALM",
45 ErrCodeInadequateSecurity: "INADEQUATE_SECURITY",
46 ErrCodeHTTP11Required: "HTTP_1_1_REQUIRED",
47 }
48
49 func (e ErrCode) String() string {
50 if s, ok := errCodeName[e]; ok {
51 return s
52 }
53 return fmt.Sprintf("unknown error code 0x%x", uint32(e))
54 }
55
56 func (e ErrCode) stringToken() string {
57 if s, ok := errCodeName[e]; ok {
58 return s
59 }
60 return fmt.Sprintf("ERR_UNKNOWN_%d", uint32(e))
61 }
62
63
64
65 type ConnectionError ErrCode
66
67 func (e ConnectionError) Error() string { return fmt.Sprintf("connection error: %s", ErrCode(e)) }
68
69
70
71 type StreamError struct {
72 StreamID uint32
73 Code ErrCode
74 Cause error
75 }
76
77
78
79
80 var errFromPeer = errors.New("received from peer")
81
82 func streamError(id uint32, code ErrCode) StreamError {
83 return StreamError{StreamID: id, Code: code}
84 }
85
86 func (e StreamError) Error() string {
87 if e.Cause != nil {
88 return fmt.Sprintf("stream error: stream ID %d; %v; %v", e.StreamID, e.Code, e.Cause)
89 }
90 return fmt.Sprintf("stream error: stream ID %d; %v", e.StreamID, e.Code)
91 }
92
93
94
95
96
97
98 type goAwayFlowError struct{}
99
100 func (goAwayFlowError) Error() string { return "connection exceeded flow control window size" }
101
102
103
104
105
106
107
108
109 type connError struct {
110 Code ErrCode
111 Reason string
112 }
113
114 func (e connError) Error() string {
115 return fmt.Sprintf("http2: connection error: %v: %v", e.Code, e.Reason)
116 }
117
118 type pseudoHeaderError string
119
120 func (e pseudoHeaderError) Error() string {
121 return fmt.Sprintf("invalid pseudo-header %q", string(e))
122 }
123
124 type duplicatePseudoHeaderError string
125
126 func (e duplicatePseudoHeaderError) Error() string {
127 return fmt.Sprintf("duplicate pseudo-header %q", string(e))
128 }
129
130 type headerFieldNameError string
131
132 func (e headerFieldNameError) Error() string {
133 return fmt.Sprintf("invalid header field name %q", string(e))
134 }
135
136 type headerFieldValueError string
137
138 func (e headerFieldValueError) Error() string {
139 return fmt.Sprintf("invalid header field value for %q", string(e))
140 }
141
142 var (
143 errMixPseudoHeaderTypes = errors.New("mix of request and response pseudo headers")
144 errPseudoAfterRegular = errors.New("pseudo header field after regular")
145 )
146
View as plain text