From d2db07ba17b2511a3d64ed897e9319a0b456c3bb Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 25 Oct 2026 23:24:56 +0000 Subject: [PATCH] Add Transport.SetT1 An http2.Transport built as a struct literal has no t1, so it ignores the HTTP/1 settings it would otherwise read from it, such as ResponseHeaderTimeout. ConfigureTransports is the only way to set t1, and it also registers the HTTP/2 transport on t1, which callers that dial their own connections, like tls-client, do not want. SetT1 complements GetT1 and lets those callers provide the settings. Co-Authored-By: Claude Opus 5.5 --- http2/transport.go | 8 ++++++++ http2/transport_test.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/http2/transport.go b/http2/transport.go index b3d56f30..623fe19f 100644 --- a/http2/transport.go +++ b/http2/transport.go @@ -174,6 +174,14 @@ func (t *Transport) GetT1() *http.Transport { return t.t1 } +// SetT1 sets the HTTP/1 Transport whose settings, such as +// ResponseHeaderTimeout and DisableKeepAlives, this transport uses. +// Unlike ConfigureTransports, it does not modify t1. +// It must be called before the transport is first used. +func (t *Transport) SetT1(t1 *http.Transport) { + t.t1 = t1 +} + func (t *Transport) maxHeaderListSize() uint32 { maxHeaderListSize, ok := t.Settings[SettingMaxHeaderListSize] diff --git a/http2/transport_test.go b/http2/transport_test.go index 57f026e8..eeca2ccc 100644 --- a/http2/transport_test.go +++ b/http2/transport_test.go @@ -2069,9 +2069,9 @@ func TestTransportResponseHeaderTimeout_Body(t *testing.T) { func testTransportResponseHeaderTimeout(t *testing.T, body bool) { ct := newClientTester(t) - ct.tr.t1 = &http.Transport{ + ct.tr.SetT1(&http.Transport{ ResponseHeaderTimeout: 5 * time.Millisecond, - } + }) ct.client = func() error { c := &http.Client{Transport: ct.tr} var err error