config_go124.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//go:build go1.24
 6
 7package http2
 8
 9import "net/http"
10
11// fillNetHTTPServerConfig sets fields in conf from srv.HTTP2.
12func fillNetHTTPServerConfig(conf *http2Config, srv *http.Server) {
13	fillNetHTTPConfig(conf, srv.HTTP2)
14}
15
16// fillNetHTTPTransportConfig sets fields in conf from tr.HTTP2.
17func fillNetHTTPTransportConfig(conf *http2Config, tr *http.Transport) {
18	fillNetHTTPConfig(conf, tr.HTTP2)
19}
20
21func fillNetHTTPConfig(conf *http2Config, h2 *http.HTTP2Config) {
22	if h2 == nil {
23		return
24	}
25	if h2.MaxConcurrentStreams != 0 {
26		conf.MaxConcurrentStreams = uint32(h2.MaxConcurrentStreams)
27	}
28	if h2.MaxEncoderHeaderTableSize != 0 {
29		conf.MaxEncoderHeaderTableSize = uint32(h2.MaxEncoderHeaderTableSize)
30	}
31	if h2.MaxDecoderHeaderTableSize != 0 {
32		conf.MaxDecoderHeaderTableSize = uint32(h2.MaxDecoderHeaderTableSize)
33	}
34	if h2.MaxConcurrentStreams != 0 {
35		conf.MaxConcurrentStreams = uint32(h2.MaxConcurrentStreams)
36	}
37	if h2.MaxReadFrameSize != 0 {
38		conf.MaxReadFrameSize = uint32(h2.MaxReadFrameSize)
39	}
40	if h2.MaxReceiveBufferPerConnection != 0 {
41		conf.MaxUploadBufferPerConnection = int32(h2.MaxReceiveBufferPerConnection)
42	}
43	if h2.MaxReceiveBufferPerStream != 0 {
44		conf.MaxUploadBufferPerStream = int32(h2.MaxReceiveBufferPerStream)
45	}
46	if h2.SendPingTimeout != 0 {
47		conf.SendPingTimeout = h2.SendPingTimeout
48	}
49	if h2.PingTimeout != 0 {
50		conf.PingTimeout = h2.PingTimeout
51	}
52	if h2.WriteByteTimeout != 0 {
53		conf.WriteByteTimeout = h2.WriteByteTimeout
54	}
55	if h2.PermitProhibitedCipherSuites {
56		conf.PermitProhibitedCipherSuites = true
57	}
58	if h2.CountError != nil {
59		conf.CountError = h2.CountError
60	}
61}