Skip to content

Commit de7450a

Browse files
committed
expose more http2 settings to client and transport
1 parent 9e2d4b1 commit de7450a

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

client.go

+57
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,63 @@ func (c *Client) EnableHTTP3() *Client {
11581158
return c
11591159
}
11601160

1161+
// SetHTTP2MaxHeaderListSize set the http2 MaxHeaderListSize,
1162+
// which is the http2 SETTINGS_MAX_HEADER_LIST_SIZE to
1163+
// send in the initial settings frame. It is how many bytes
1164+
// of response headers are allowed. Unlike the http2 spec, zero here
1165+
// means to use a default limit (currently 10MB). If you actually
1166+
// want to advertise an unlimited value to the peer, Transport
1167+
// interprets the highest possible value here (0xffffffff or 1<<32-1)
1168+
// to mean no limit.
1169+
func (c *Client) SetHTTP2MaxHeaderListSize(max uint32) *Client {
1170+
c.t.SetHTTP2MaxHeaderListSize(max)
1171+
return c
1172+
}
1173+
1174+
// SetHTTP2StrictMaxConcurrentStreams set the http2
1175+
// StrictMaxConcurrentStreams, which controls whether the
1176+
// server's SETTINGS_MAX_CONCURRENT_STREAMS should be respected
1177+
// globally. If false, new TCP connections are created to the
1178+
// server as needed to keep each under the per-connection
1179+
// SETTINGS_MAX_CONCURRENT_STREAMS limit. If true, the
1180+
// server's SETTINGS_MAX_CONCURRENT_STREAMS is interpreted as
1181+
// a global limit and callers of RoundTrip block when needed,
1182+
// waiting for their turn.
1183+
func (c *Client) SetHTTP2StrictMaxConcurrentStreams(strict bool) *Client {
1184+
c.t.SetHTTP2StrictMaxConcurrentStreams(strict)
1185+
return c
1186+
}
1187+
1188+
// SetHTTP2ReadIdleTimeout set the http2 ReadIdleTimeout,
1189+
// which is the timeout after which a health check using ping
1190+
// frame will be carried out if no frame is received on the connection.
1191+
// Note that a ping response will is considered a received frame, so if
1192+
// there is no other traffic on the connection, the health check will
1193+
// be performed every ReadIdleTimeout interval.
1194+
// If zero, no health check is performed.
1195+
func (c *Client) SetHTTP2ReadIdleTimeout(timeout time.Duration) *Client {
1196+
c.t.SetHTTP2ReadIdleTimeout(timeout)
1197+
return c
1198+
}
1199+
1200+
// SetHTTP2PingTimeout set the http2 PingTimeout, which is the timeout
1201+
// after which the connection will be closed if a response to Ping is
1202+
// not received.
1203+
// Defaults to 15s
1204+
func (c *Client) SetHTTP2PingTimeout(timeout time.Duration) *Client {
1205+
c.t.SetHTTP2PingTimeout(timeout)
1206+
return c
1207+
}
1208+
1209+
// SetHTTP2WriteByteTimeout set the http2 WriteByteTimeout, which is the
1210+
// timeout after which the connection will be closed no data can be written
1211+
// to it. The timeout begins when data is available to write, and is
1212+
// extended whenever any bytes are written.
1213+
func (c *Client) SetHTTP2WriteByteTimeout(timeout time.Duration) *Client {
1214+
c.t.SetHTTP2WriteByteTimeout(timeout)
1215+
return c
1216+
}
1217+
11611218
// NewClient is the alias of C
11621219
func NewClient() *Client {
11631220
return C()

transport.go

+57
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,63 @@ func (t *Transport) SetMaxResponseHeaderBytes(max int64) *Transport {
345345
return t
346346
}
347347

348+
// SetHTTP2MaxHeaderListSize set the http2 MaxHeaderListSize,
349+
// which is the http2 SETTINGS_MAX_HEADER_LIST_SIZE to
350+
// send in the initial settings frame. It is how many bytes
351+
// of response headers are allowed. Unlike the http2 spec, zero here
352+
// means to use a default limit (currently 10MB). If you actually
353+
// want to advertise an unlimited value to the peer, Transport
354+
// interprets the highest possible value here (0xffffffff or 1<<32-1)
355+
// to mean no limit.
356+
func (t *Transport) SetHTTP2MaxHeaderListSize(max uint32) *Transport {
357+
t.t2.MaxHeaderListSize = max
358+
return t
359+
}
360+
361+
// SetHTTP2StrictMaxConcurrentStreams set the http2
362+
// StrictMaxConcurrentStreams, which controls whether the
363+
// server's SETTINGS_MAX_CONCURRENT_STREAMS should be respected
364+
// globally. If false, new TCP connections are created to the
365+
// server as needed to keep each under the per-connection
366+
// SETTINGS_MAX_CONCURRENT_STREAMS limit. If true, the
367+
// server's SETTINGS_MAX_CONCURRENT_STREAMS is interpreted as
368+
// a global limit and callers of RoundTrip block when needed,
369+
// waiting for their turn.
370+
func (t *Transport) SetHTTP2StrictMaxConcurrentStreams(strict bool) *Transport {
371+
t.t2.StrictMaxConcurrentStreams = strict
372+
return t
373+
}
374+
375+
// SetHTTP2ReadIdleTimeout set the http2 ReadIdleTimeout,
376+
// which is the timeout after which a health check using ping
377+
// frame will be carried out if no frame is received on the connection.
378+
// Note that a ping response will is considered a received frame, so if
379+
// there is no other traffic on the connection, the health check will
380+
// be performed every ReadIdleTimeout interval.
381+
// If zero, no health check is performed.
382+
func (t *Transport) SetHTTP2ReadIdleTimeout(timeout time.Duration) *Transport {
383+
t.t2.ReadIdleTimeout = timeout
384+
return t
385+
}
386+
387+
// SetHTTP2PingTimeout set the http2 PingTimeout, which is the timeout
388+
// after which the connection will be closed if a response to Ping is
389+
// not received.
390+
// Defaults to 15s
391+
func (t *Transport) SetHTTP2PingTimeout(timeout time.Duration) *Transport {
392+
t.t2.PingTimeout = timeout
393+
return t
394+
}
395+
396+
// SetHTTP2WriteByteTimeout set the http2 WriteByteTimeout, which is the
397+
// timeout after which the connection will be closed no data can be written
398+
// to it. The timeout begins when data is available to write, and is
399+
// extended whenever any bytes are written.
400+
func (t *Transport) SetHTTP2WriteByteTimeout(timeout time.Duration) *Transport {
401+
t.t2.WriteByteTimeout = timeout
402+
return t
403+
}
404+
348405
// SetTLSClientConfig set the custom TLSClientConfig, which specifies the TLS configuration to
349406
// use with tls.Client.
350407
// If nil, the default configuration is used.

0 commit comments

Comments
 (0)