Skip to content

Commit f84dea3

Browse files
committedAug 29, 2024
net/http: add HTTP2Config
Add a field to Server and Transport containing HTTP/2 configuration parameters. This field will have no effect until golang.org/x/net/http2 is updated to make use of it, and h2_bundle.go is updated with the new http2 package. For #67813 Change-Id: I81d7f8e9ddea78f9666383983aec43e3884c13ed Reviewed-on: https://go-review.googlesource.com/c/go/+/602175 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
1 parent 4f852b9 commit f84dea3

File tree

6 files changed

+98
-0
lines changed

6 files changed

+98
-0
lines changed
 

‎api/next/67813.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pkg net/http, type HTTP2Config struct #67813
2+
pkg net/http, type HTTP2Config struct, CountError func(string) #67813
3+
pkg net/http, type HTTP2Config struct, MaxConcurrentStreams int #67813
4+
pkg net/http, type HTTP2Config struct, MaxDecoderHeaderTableSize int #67813
5+
pkg net/http, type HTTP2Config struct, MaxEncoderHeaderTableSize int #67813
6+
pkg net/http, type HTTP2Config struct, MaxReadFrameSize int #67813
7+
pkg net/http, type HTTP2Config struct, MaxReceiveBufferPerConnection int #67813
8+
pkg net/http, type HTTP2Config struct, MaxReceiveBufferPerStream int #67813
9+
pkg net/http, type HTTP2Config struct, PermitProhibitedCipherSuites bool #67813
10+
pkg net/http, type HTTP2Config struct, PingTimeout time.Duration #67813
11+
pkg net/http, type HTTP2Config struct, SendPingTimeout time.Duration #67813
12+
pkg net/http, type HTTP2Config struct, WriteByteTimeout time.Duration #67813
13+
pkg net/http, type Server struct, HTTP2 *HTTP2Config #67813
14+
pkg net/http, type Transport struct, HTTP2 *HTTP2Config #67813
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Transport] and [Server] now have an HTTP2 field which permits
2+
configuring HTTP/2 protocol settings.

‎src/net/http/http.go

+65
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,68 @@ type Pusher interface {
163163
// is not supported on the underlying connection.
164164
Push(target string, opts *PushOptions) error
165165
}
166+
167+
// HTTP2Config defines HTTP/2 configuration parameters common to
168+
// both [Transport] and [Server].
169+
type HTTP2Config struct {
170+
// MaxConcurrentStreams optionally specifies the number of
171+
// concurrent streams that a peer may have open at a time.
172+
// If zero, MaxConcurrentStreams defaults to at least 100.
173+
MaxConcurrentStreams int
174+
175+
// MaxDecoderHeaderTableSize optionally specifies an upper limit for the
176+
// size of the header compression table used for decoding headers sent
177+
// by the peer.
178+
// A valid value is less than 4MiB.
179+
// If zero or invalid, a default value is used.
180+
MaxDecoderHeaderTableSize int
181+
182+
// MaxEncoderHeaderTableSize optionally specifies an upper limit for the
183+
// header compression table used for sending headers to the peer.
184+
// A valid value is less than 4MiB.
185+
// If zero or invalid, a default value is used.
186+
MaxEncoderHeaderTableSize int
187+
188+
// MaxReadFrameSize optionally specifies the largest frame
189+
// this endpoint is willing to read.
190+
// A valid value is between 16KiB and 16MiB, inclusive.
191+
// If zero or invalid, a default value is used.
192+
MaxReadFrameSize int
193+
194+
// MaxReceiveBufferPerConnection is the maximum size of the
195+
// flow control window for data received on a connection.
196+
// A valid value is at least 64KiB and less than 4MiB.
197+
// If invalid, a default value is used.
198+
MaxReceiveBufferPerConnection int
199+
200+
// MaxReceiveBufferPerStream is the maximum size of
201+
// the flow control window for data received on a stream (request).
202+
// A valid value is less than 4MiB.
203+
// If zero or invalid, a default value is used.
204+
MaxReceiveBufferPerStream int
205+
206+
// SendPingTimeout is the timeout after which a health check using a ping
207+
// frame will be carried out if no frame is received on a connection.
208+
// If zero, no health check is performed.
209+
SendPingTimeout time.Duration
210+
211+
// PingTimeout is the timeout after which a connection will be closed
212+
// if a response to a ping is not received.
213+
// If zero, a default of 15 seconds is used.
214+
PingTimeout time.Duration
215+
216+
// WriteByteTimeout is the timeout after which a connection will be
217+
// closed if no data can be written to it. The timeout begins when data is
218+
// available to write, and is extended whenever any bytes are written.
219+
WriteByteTimeout time.Duration
220+
221+
// PermitProhibitedCipherSuites, if true, permits the use of
222+
// cipher suites prohibited by the HTTP/2 spec.
223+
PermitProhibitedCipherSuites bool
224+
225+
// CountError, if non-nil, is called on HTTP/2 errors.
226+
// It is intended to increment a metric for monitoring.
227+
// The errType contains only lowercase letters, digits, and underscores
228+
// (a-z, 0-9, _).
229+
CountError func(errType string)
230+
}

‎src/net/http/server.go

+6
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,12 @@ type Server struct {
29732973
// value.
29742974
ConnContext func(ctx context.Context, c net.Conn) context.Context
29752975

2976+
// HTTP2 configures HTTP/2 connections.
2977+
//
2978+
// This field does not yet have any effect.
2979+
// See https://go.dev/issue/67813.
2980+
HTTP2 *HTTP2Config
2981+
29762982
inShutdown atomic.Bool // true when server is in shutdown
29772983

29782984
disableKeepAlives atomic.Bool

‎src/net/http/transport.go

+10
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ type Transport struct {
293293
// To use a custom dialer or TLS config and still attempt HTTP/2
294294
// upgrades, set this to true.
295295
ForceAttemptHTTP2 bool
296+
297+
// HTTP2 configures HTTP/2 connections.
298+
//
299+
// This field does not yet have any effect.
300+
// See https://go.dev/issue/67813.
301+
HTTP2 *HTTP2Config
296302
}
297303

298304
func (t *Transport) writeBufferSize() int {
@@ -338,6 +344,10 @@ func (t *Transport) Clone() *Transport {
338344
if t.TLSClientConfig != nil {
339345
t2.TLSClientConfig = t.TLSClientConfig.Clone()
340346
}
347+
if t.HTTP2 != nil {
348+
t2.HTTP2 = &HTTP2Config{}
349+
*t2.HTTP2 = *t.HTTP2
350+
}
341351
if !t.tlsNextProtoWasNil {
342352
npm := map[string]func(authority string, c *tls.Conn) RoundTripper{}
343353
for k, v := range t.TLSNextProto {

‎src/net/http/transport_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -6328,6 +6328,7 @@ func TestTransportClone(t *testing.T) {
63286328
GetProxyConnectHeader: func(context.Context, *url.URL, string) (Header, error) { return nil, nil },
63296329
MaxResponseHeaderBytes: 1,
63306330
ForceAttemptHTTP2: true,
6331+
HTTP2: &HTTP2Config{MaxConcurrentStreams: 1},
63316332
TLSNextProto: map[string]func(authority string, c *tls.Conn) RoundTripper{
63326333
"foo": func(authority string, c *tls.Conn) RoundTripper { panic("") },
63336334
},

0 commit comments

Comments
 (0)
Please sign in to comment.