From c761d477f94b64d85c8e185c92a9d1b3f3cd6d08 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Tue, 26 May 2026 17:08:11 +0300 Subject: [PATCH] fix: Get rid of deprecated x/net/http2/h2c Signed-off-by: Oleksandr Redko --- flytestdlib/.golangci.yml | 7 +++++++ flytestdlib/app/app.go | 23 +++++++++++++---------- go.mod | 2 +- runs/test/api/setup_test.go | 14 ++++++++++---- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/flytestdlib/.golangci.yml b/flytestdlib/.golangci.yml index 0dcfd97b3a3..ba836036fc6 100644 --- a/flytestdlib/.golangci.yml +++ b/flytestdlib/.golangci.yml @@ -5,6 +5,7 @@ linters: default: none enable: - copyloopvar + - depguard - dupl - errcheck - ginkgolinter @@ -22,6 +23,12 @@ linters: - unparam - unused settings: + depguard: + rules: + no-h2c: + deny: + - pkg: golang.org/x/net/http2/h2c + desc: "deprecated: use net/http with http.Protocols.SetUnencryptedHTTP2(true)" revive: rules: - name: comment-spacings diff --git a/flytestdlib/app/app.go b/flytestdlib/app/app.go index 0dcdf88e25f..49dccb350b0 100644 --- a/flytestdlib/app/app.go +++ b/flytestdlib/app/app.go @@ -15,8 +15,6 @@ import ( "time" "github.com/spf13/cobra" - "golang.org/x/net/http2" - "golang.org/x/net/http2/h2c" "github.com/flyteorg/flyte/v2/flytestdlib/config" "github.com/flyteorg/flyte/v2/flytestdlib/config/viper" @@ -118,8 +116,9 @@ func (a *App) serve(ctx context.Context) error { addr := fmt.Sprintf("%s:%d", sc.Host, sc.Port) server = &http.Server{ - Addr: addr, - Handler: h2c.NewHandler(handler, &http2.Server{}), + Addr: addr, + Handler: handler, + Protocols: httpProtocols(), } wg.Add(1) @@ -197,17 +196,21 @@ func (a *App) serve(ctx context.Context) error { return shutdownErr } +func httpProtocols() *http.Protocols { + protocols := &http.Protocols{} + protocols.SetHTTP1(true) + protocols.SetUnencryptedHTTP2(true) + return protocols +} + // requestGzipDecompressMiddleware pre-decompresses request bodies that carry // Content-Encoding: gzip before they reach the connect-rpc handler. // // Some HTTP clients (e.g. pyqwest used by the Python connectrpc SDK) compress // the request body at the application level and set Content-Encoding: gzip, -// but also use chunked transfer encoding for larger payloads. Go's h2c -// framing delivers the body in chunks, so by the time connect-go calls -// gzip.NewReader on the raw body stream the first bytes it receives may be a -// chunk-size line rather than the gzip magic bytes, causing "gzip: invalid -// header". Pre-reading and fully decompressing the body here, before h2c -// framing is involved, sidesteps the problem entirely. +// but the stream may not begin with gzip magic bytes by the time connect-go +// attempts to wrap it, causing "gzip: invalid header". Pre-reading and fully +// decompressing the body here sidesteps the problem entirely. func requestGzipDecompressMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if strings.EqualFold(r.Header.Get("Content-Encoding"), "gzip") { diff --git a/go.mod b/go.mod index 0befedc98e5..1a4c52014a7 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,6 @@ require ( go.opentelemetry.io/otel/sdk v1.37.0 go.opentelemetry.io/otel/trace v1.37.0 golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 - golang.org/x/net v0.54.0 golang.org/x/oauth2 v0.36.0 golang.org/x/sync v0.20.0 golang.org/x/time v0.15.0 @@ -206,6 +205,7 @@ require ( go.uber.org/zap v1.27.0 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect golang.org/x/crypto v0.51.0 // indirect + golang.org/x/net v0.54.0 // indirect golang.org/x/sys v0.44.0 // indirect golang.org/x/term v0.43.0 // indirect golang.org/x/text v0.37.0 // indirect diff --git a/runs/test/api/setup_test.go b/runs/test/api/setup_test.go index d243ed1e07e..ec18de42f2b 100644 --- a/runs/test/api/setup_test.go +++ b/runs/test/api/setup_test.go @@ -12,8 +12,6 @@ import ( embeddedpostgres "github.com/fergusstrange/embedded-postgres" "github.com/jmoiron/sqlx" - "golang.org/x/net/http2" - "golang.org/x/net/http2/h2c" "github.com/flyteorg/flyte/v2/flytestdlib/database" "github.com/flyteorg/flyte/v2/gen/go/flyteidl2/actions/actionsconnect" @@ -136,8 +134,9 @@ func TestMain(m *testing.M) { endpoint = fmt.Sprintf("http://localhost:%d", testPort) testServer = &http.Server{ - Addr: fmt.Sprintf(":%d", testPort), - Handler: h2c.NewHandler(mux, &http2.Server{}), + Addr: fmt.Sprintf(":%d", testPort), + Handler: mux, + Protocols: httpProtocols(), } // Start server in background @@ -173,6 +172,13 @@ func TestMain(m *testing.M) { exitCode = m.Run() } +func httpProtocols() *http.Protocols { + protocols := &http.Protocols{} + protocols.SetHTTP1(true) + protocols.SetUnencryptedHTTP2(true) + return protocols +} + // waitForServer waits for the server to be ready func waitForServer(url string, timeout time.Duration) bool { client := &http.Client{Timeout: 1 * time.Second}