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

     1  // Copyright 2025 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  const (
     8  	// https://www.rfc-editor.org/rfc/rfc9114.html#section-7.2.4.1
     9  	settingsMaxFieldSectionSize = 0x06
    10  
    11  	// https://www.rfc-editor.org/rfc/rfc9204.html#section-5
    12  	settingsQPACKMaxTableCapacity = 0x01
    13  	settingsQPACKBlockedStreams   = 0x07
    14  )
    15  
    16  // writeSettings writes a complete SETTINGS frame.
    17  // Its parameter is a list of alternating setting types and values.
    18  func (st *stream) writeSettings(settings ...int64) {
    19  	var size int64
    20  	for _, s := range settings {
    21  		// Settings values that don't fit in a QUIC varint ([0,2^62)) will panic here.
    22  		size += int64(sizeVarint(uint64(s)))
    23  	}
    24  	st.writeVarint(int64(frameTypeSettings))
    25  	st.writeVarint(size)
    26  	for _, s := range settings {
    27  		st.writeVarint(s)
    28  	}
    29  }
    30  
    31  // readSettings reads a complete SETTINGS frame, including the frame header.
    32  func (st *stream) readSettings(f func(settingType, value int64) error) error {
    33  	frameType, err := st.readFrameHeader()
    34  	if err != nil || frameType != frameTypeSettings {
    35  		return &connectionError{
    36  			code:    errH3MissingSettings,
    37  			message: "settings not sent on control stream",
    38  		}
    39  	}
    40  	for st.lim > 0 {
    41  		settingsType, err := st.readVarint()
    42  		if err != nil {
    43  			return err
    44  		}
    45  		settingsValue, err := st.readVarint()
    46  		if err != nil {
    47  			return err
    48  		}
    49  
    50  		// Use of HTTP/2 settings where there is no corresponding HTTP/3 setting
    51  		// is an error.
    52  		// https://www.rfc-editor.org/rfc/rfc9114.html#section-7.2.4.1-5
    53  		switch settingsType {
    54  		case 0x02, 0x03, 0x04, 0x05:
    55  			return &connectionError{
    56  				code:    errH3SettingsError,
    57  				message: "use of reserved setting",
    58  			}
    59  		}
    60  
    61  		if err := f(settingsType, settingsValue); err != nil {
    62  			return err
    63  		}
    64  	}
    65  	return st.endFrame()
    66  }
    67  

View as plain text