cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
h2mux/error.go
64lines · modecode
| 1 | package h2mux |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "golang.org/x/net/http2" |
| 7 | ) |
| 8 | |
| 9 | var ( |
| 10 | // HTTP2 error codes: https://http2.github.io/http2-spec/#ErrorCodes |
| 11 | ErrHandshakeTimeout = MuxerHandshakeError{"1000 handshake timeout"} |
| 12 | ErrBadHandshakeNotSettings = MuxerHandshakeError{"1001 unexpected response"} |
| 13 | ErrBadHandshakeUnexpectedAck = MuxerHandshakeError{"1002 unexpected response"} |
| 14 | ErrBadHandshakeNoMagic = MuxerHandshakeError{"1003 unexpected response"} |
| 15 | ErrBadHandshakeWrongMagic = MuxerHandshakeError{"1004 connected to endpoint of wrong type"} |
| 16 | ErrBadHandshakeNotSettingsAck = MuxerHandshakeError{"1005 unexpected response"} |
| 17 | ErrBadHandshakeUnexpectedSettings = MuxerHandshakeError{"1006 unexpected response"} |
| 18 | |
| 19 | ErrUnexpectedFrameType = MuxerProtocolError{"2001 unexpected frame type", http2.ErrCodeProtocol} |
| 20 | ErrUnknownStream = MuxerProtocolError{"2002 unknown stream", http2.ErrCodeProtocol} |
| 21 | ErrInvalidStream = MuxerProtocolError{"2003 invalid stream", http2.ErrCodeProtocol} |
| 22 | |
| 23 | ErrStreamHeadersSent = MuxerApplicationError{"3000 headers already sent"} |
| 24 | ErrConnectionClosed = MuxerApplicationError{"3001 connection closed"} |
| 25 | ErrConnectionDropped = MuxerApplicationError{"3002 connection dropped"} |
| 26 | ErrOpenStreamTimeout = MuxerApplicationError{"3003 open stream timeout"} |
| 27 | ErrResponseHeadersTimeout = MuxerApplicationError{"3004 timeout waiting for initial response headers"} |
| 28 | |
| 29 | ErrClosedStream = MuxerStreamError{"4000 stream closed", http2.ErrCodeStreamClosed} |
| 30 | ) |
| 31 | |
| 32 | type MuxerHandshakeError struct { |
| 33 | cause string |
| 34 | } |
| 35 | |
| 36 | func (e MuxerHandshakeError) Error() string { |
| 37 | return fmt.Sprintf("Handshake error: %s", e.cause) |
| 38 | } |
| 39 | |
| 40 | type MuxerProtocolError struct { |
| 41 | cause string |
| 42 | h2code http2.ErrCode |
| 43 | } |
| 44 | |
| 45 | func (e MuxerProtocolError) Error() string { |
| 46 | return fmt.Sprintf("Protocol error: %s", e.cause) |
| 47 | } |
| 48 | |
| 49 | type MuxerApplicationError struct { |
| 50 | cause string |
| 51 | } |
| 52 | |
| 53 | func (e MuxerApplicationError) Error() string { |
| 54 | return fmt.Sprintf("Application error: %s", e.cause) |
| 55 | } |
| 56 | |
| 57 | type MuxerStreamError struct { |
| 58 | cause string |
| 59 | h2code http2.ErrCode |
| 60 | } |
| 61 | |
| 62 | func (e MuxerStreamError) Error() string { |
| 63 | return fmt.Sprintf("Stream error: %s", e.cause) |
| 64 | } |
| 65 | |