Source file src/vendor/golang.org/x/net/internal/http3/http3.go

     1  // Copyright 2024 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 http3
     6  
     7  import (
     8  	"context"
     9  	"fmt"
    10  )
    11  
    12  // Stream types.
    13  //
    14  // For unidirectional streams, the value is the stream type sent over the wire.
    15  //
    16  // For bidirectional streams (which are always request streams),
    17  // the value is arbitrary and never sent on the wire.
    18  type streamType int64
    19  
    20  const (
    21  	// Bidirectional request stream.
    22  	// All bidirectional streams are request streams.
    23  	// This stream type is never sent over the wire.
    24  	//
    25  	// https://www.rfc-editor.org/rfc/rfc9114.html#section-6.1
    26  	streamTypeRequest = streamType(-1)
    27  
    28  	// https://www.rfc-editor.org/rfc/rfc9114.html#section-6.2
    29  	streamTypeControl = streamType(0x00)
    30  	streamTypePush    = streamType(0x01)
    31  
    32  	// https://www.rfc-editor.org/rfc/rfc9204.html#section-4.2
    33  	streamTypeEncoder = streamType(0x02)
    34  	streamTypeDecoder = streamType(0x03)
    35  )
    36  
    37  // canceledCtx is a canceled Context.
    38  // Used for performing non-blocking QUIC operations.
    39  var canceledCtx = func() context.Context {
    40  	ctx, cancel := context.WithCancel(context.Background())
    41  	cancel()
    42  	return ctx
    43  }()
    44  
    45  func (stype streamType) String() string {
    46  	switch stype {
    47  	case streamTypeRequest:
    48  		return "request"
    49  	case streamTypeControl:
    50  		return "control"
    51  	case streamTypePush:
    52  		return "push"
    53  	case streamTypeEncoder:
    54  		return "encoder"
    55  	case streamTypeDecoder:
    56  		return "decoder"
    57  	default:
    58  		return "unknown"
    59  	}
    60  }
    61  
    62  // Frame types.
    63  type frameType int64
    64  
    65  const (
    66  	// https://www.rfc-editor.org/rfc/rfc9114.html#section-7.2
    67  	frameTypeData        = frameType(0x00)
    68  	frameTypeHeaders     = frameType(0x01)
    69  	frameTypeCancelPush  = frameType(0x03)
    70  	frameTypeSettings    = frameType(0x04)
    71  	frameTypePushPromise = frameType(0x05)
    72  	frameTypeGoaway      = frameType(0x07)
    73  	frameTypeMaxPushID   = frameType(0x0d)
    74  )
    75  
    76  func (ftype frameType) String() string {
    77  	switch ftype {
    78  	case frameTypeData:
    79  		return "DATA"
    80  	case frameTypeHeaders:
    81  		return "HEADERS"
    82  	case frameTypeCancelPush:
    83  		return "CANCEL_PUSH"
    84  	case frameTypeSettings:
    85  		return "SETTINGS"
    86  	case frameTypePushPromise:
    87  		return "PUSH_PROMISE"
    88  	case frameTypeGoaway:
    89  		return "GOAWAY"
    90  	case frameTypeMaxPushID:
    91  		return "MAX_PUSH_ID"
    92  	default:
    93  		return fmt.Sprintf("UNKNOWN_%d", int64(ftype))
    94  	}
    95  }
    96  

View as plain text