github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/net/http2/errors.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package http2
     6  
     7  import "fmt"
     8  
     9  // An ErrCode is an unsigned 32-bit error code as defined in the HTTP/2 spec.
    10  type ErrCode uint32
    11  
    12  const (
    13  	ErrCodeNo                 ErrCode = 0x0
    14  	ErrCodeProtocol           ErrCode = 0x1
    15  	ErrCodeInternal           ErrCode = 0x2
    16  	ErrCodeFlowControl        ErrCode = 0x3
    17  	ErrCodeSettingsTimeout    ErrCode = 0x4
    18  	ErrCodeStreamClosed       ErrCode = 0x5
    19  	ErrCodeFrameSize          ErrCode = 0x6
    20  	ErrCodeRefusedStream      ErrCode = 0x7
    21  	ErrCodeCancel             ErrCode = 0x8
    22  	ErrCodeCompression        ErrCode = 0x9
    23  	ErrCodeConnect            ErrCode = 0xa
    24  	ErrCodeEnhanceYourCalm    ErrCode = 0xb
    25  	ErrCodeInadequateSecurity ErrCode = 0xc
    26  	ErrCodeHTTP11Required     ErrCode = 0xd
    27  )
    28  
    29  var errCodeName = map[ErrCode]string{
    30  	ErrCodeNo:                 "NO_ERROR",
    31  	ErrCodeProtocol:           "PROTOCOL_ERROR",
    32  	ErrCodeInternal:           "INTERNAL_ERROR",
    33  	ErrCodeFlowControl:        "FLOW_CONTROL_ERROR",
    34  	ErrCodeSettingsTimeout:    "SETTINGS_TIMEOUT",
    35  	ErrCodeStreamClosed:       "STREAM_CLOSED",
    36  	ErrCodeFrameSize:          "FRAME_SIZE_ERROR",
    37  	ErrCodeRefusedStream:      "REFUSED_STREAM",
    38  	ErrCodeCancel:             "CANCEL",
    39  	ErrCodeCompression:        "COMPRESSION_ERROR",
    40  	ErrCodeConnect:            "CONNECT_ERROR",
    41  	ErrCodeEnhanceYourCalm:    "ENHANCE_YOUR_CALM",
    42  	ErrCodeInadequateSecurity: "INADEQUATE_SECURITY",
    43  	ErrCodeHTTP11Required:     "HTTP_1_1_REQUIRED",
    44  }
    45  
    46  func (e ErrCode) String() string {
    47  	if s, ok := errCodeName[e]; ok {
    48  		return s
    49  	}
    50  	return fmt.Sprintf("unknown error code 0x%x", uint32(e))
    51  }
    52  
    53  // ConnectionError is an error that results in the termination of the
    54  // entire connection.
    55  type ConnectionError ErrCode
    56  
    57  func (e ConnectionError) Error() string { return fmt.Sprintf("connection error: %s", ErrCode(e)) }
    58  
    59  // StreamError is an error that only affects one stream within an
    60  // HTTP/2 connection.
    61  type StreamError struct {
    62  	StreamID uint32
    63  	Code     ErrCode
    64  }
    65  
    66  func (e StreamError) Error() string {
    67  	return fmt.Sprintf("stream error: stream ID %d; %v", e.StreamID, e.Code)
    68  }
    69  
    70  // 6.9.1 The Flow Control Window
    71  // "If a sender receives a WINDOW_UPDATE that causes a flow control
    72  // window to exceed this maximum it MUST terminate either the stream
    73  // or the connection, as appropriate. For streams, [...]; for the
    74  // connection, a GOAWAY frame with a FLOW_CONTROL_ERROR code."
    75  type goAwayFlowError struct{}
    76  
    77  func (goAwayFlowError) Error() string { return "connection exceeded flow control window size" }
    78  
    79  // connErrorReason wraps a ConnectionError with an informative error about why it occurs.
    80  
    81  // Errors of this type are only returned by the frame parser functions
    82  // and converted into ConnectionError(ErrCodeProtocol).
    83  type connError struct {
    84  	Code   ErrCode
    85  	Reason string
    86  }
    87  
    88  func (e connError) Error() string {
    89  	return fmt.Sprintf("http2: connection error: %v: %v", e.Code, e.Reason)
    90  }