go.uber.org/yarpc@v1.72.1/transport/http/constants.go (about)

     1  // Copyright (c) 2022 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package http
    22  
    23  import "time"
    24  
    25  // TransportName is the name of the transport.
    26  //
    27  // This value is what is used as transport.Request#Transport and transport.Namer
    28  // for Outbounds.
    29  const TransportName = "http"
    30  
    31  var (
    32  	defaultConnTimeout     = 500 * time.Millisecond
    33  	defaultInnocenceWindow = 5 * time.Second
    34  	defaultIdleConnTimeout = 15 * time.Minute
    35  )
    36  
    37  // HTTP headers used in requests and responses to send YARPC metadata.
    38  const (
    39  	// Name of the service sending the request. This corresponds to the
    40  	// Request.Caller attribute.
    41  	CallerHeader = "Rpc-Caller"
    42  
    43  	// Name of the procedure of the caller sending the request. This corresponds to the
    44  	// Request.CallerProcedure attribute.
    45  	CallerProcedureHeader = "Rpc-Caller-Procedure"
    46  
    47  	// Name of the encoding used for the request body. This corresponds to the
    48  	// Request.Encoding attribute.
    49  	EncodingHeader = "Rpc-Encoding"
    50  
    51  	// Amount of time (in milliseconds) within which the request is expected
    52  	// to finish.
    53  	TTLMSHeader = "Context-TTL-MS"
    54  
    55  	// Name of the procedure being called. This corresponds to the
    56  	// Request.Procedure attribute.
    57  	ProcedureHeader = "Rpc-Procedure"
    58  
    59  	// Name of the service to which the request is being sent. This
    60  	// corresponds to the Request.Service attribute. This header is also used
    61  	// in responses to ensure requests are processed by the correct service.
    62  	ServiceHeader = "Rpc-Service"
    63  
    64  	// Shard key used by the destined service to shard the request. This
    65  	// corresponds to the Request.ShardKey attribute.
    66  	ShardKeyHeader = "Rpc-Shard-Key"
    67  
    68  	// The traffic group responsible for handling the request. This
    69  	// corresponds to the Request.RoutingKey attribute.
    70  	RoutingKeyHeader = "Rpc-Routing-Key"
    71  
    72  	// A service that can proxy the destined service. This corresponds to the
    73  	// Request.RoutingDelegate attribute.
    74  	RoutingDelegateHeader = "Rpc-Routing-Delegate"
    75  
    76  	// Whether the response body contains an application error.
    77  	ApplicationStatusHeader = "Rpc-Status"
    78  
    79  	// ErrorCodeHeader contains the string representation of the error code.
    80  	ErrorCodeHeader = "Rpc-Error-Code"
    81  
    82  	// ErrorNameHeader contains the name of a user-defined error.
    83  	ErrorNameHeader = "Rpc-Error-Name"
    84  
    85  	// ErrorMessageHeader contains the message of an error, if the
    86  	// BothResponseError feature is enabled.
    87  	ErrorMessageHeader = "Rpc-Error-Message"
    88  
    89  	// ErrorDetailsHeader contains the marshaled bytes of an error. Because
    90  	// error details are mainly a gRPC concept, we use the header key name that
    91  	// gRPC uses.
    92  	// https://github.com/grpc/grpc-go/blob/04ea82009cdb9ecdefc6289f4c93ec919a10b3b6/internal/transport/handler_server.go#L218
    93  	ErrorDetailsHeader = "Grpc-Status-Details-Bin"
    94  
    95  	// AcceptsBothResponseErrorHeader says that the BothResponseError
    96  	// feature is supported on the client. If the value is "true",
    97  	// this indicates true.
    98  	AcceptsBothResponseErrorHeader = "Rpc-Accepts-Both-Response-Error"
    99  
   100  	// BothResponseErrorHeader says that the BothResponseError
   101  	// feature is supported on the server. If any non-empty value is set,
   102  	// this indicates true.
   103  	BothResponseErrorHeader = "Rpc-Both-Response-Error"
   104  )
   105  
   106  const (
   107  	// Headers for propagating transport.ApplicationErrorMeta.
   108  	_applicationErrorNameHeader    = "Rpc-Application-Error-Name"
   109  	_applicationErrorCodeHeader    = "Rpc-Application-Error-Code"
   110  	_applicationErrorDetailsHeader = "Rpc-Application-Error-Details"
   111  
   112  	// largest header value length for `transport.ApplicationErrorMeta#Details`
   113  	_maxAppErrDetailsHeaderLen = 256
   114  	// truncated message if we've exceeded the '_maxAppErrDetailsHeaderLen'
   115  	_truncatedHeaderMessage = " (truncated)"
   116  )
   117  
   118  // Valid values for the Rpc-Status header.
   119  const (
   120  	// The request was successful.
   121  	ApplicationSuccessStatus = "success"
   122  
   123  	// An error occurred. The response body contains an application header.
   124  	ApplicationErrorStatus = "error"
   125  
   126  	// AcceptTrue is the true value used for accept headers.
   127  	AcceptTrue = "true"
   128  )
   129  
   130  // ApplicationHeaderPrefix is the prefix added to application header keys to
   131  // send them in requests or responses.
   132  const ApplicationHeaderPrefix = "Rpc-Header-"
   133  
   134  const (
   135  	_http2AuthorityPseudoHeader = ":authority"
   136  	_http2MethodPseudoHeader    = ":method"
   137  	_http2PathPseudoHeader      = ":path"
   138  	_http2SchemePseudoHeader    = ":scheme"
   139  )
   140  
   141  var (
   142  	// list of pseusdo htt2 headers from https://tools.ietf.org/html/rfc7540#section-8.1.2.3
   143  	_http2PseudoHeaders = []string{
   144  		_http2AuthorityPseudoHeader,
   145  		_http2MethodPseudoHeader,
   146  		_http2PathPseudoHeader,
   147  		_http2SchemePseudoHeader,
   148  	}
   149  )