From 2fa7c43d3154b1e4cdcedabd7649755d8244a7ad Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 23 Oct 2026 19:26:47 -0400 Subject: [PATCH] api/server/router/grpc: fix linting for deprecated http2 code Signed-off-by: Sebastiaan van Stijn (cherry picked from commit c47560390bb4bbd3f207978d2fa534fd332727b2) The code lives in api/server/router/grpc on this branch. The comment drops upstream's pointer to native gRPC over the Docker socket and the TODO to remove the /grpc endpoint: this branch has no native gRPC support, so /grpc is the only way to reach the daemon's gRPC services. Signed-off-by: Cory Snider --- api/server/router/grpc/grpc.go | 4 ++-- api/server/router/grpc/grpc_routes.go | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/api/server/router/grpc/grpc.go b/api/server/router/grpc/grpc.go index 2a74f50ea7..cf56187781 100644 --- a/api/server/router/grpc/grpc.go +++ b/api/server/router/grpc/grpc.go @@ -20,7 +20,7 @@ import ( type grpcRouter struct { routes []router.Route grpcServer *grpc.Server - h2Server *http2.Server + h2Server *http2.Server //nolint:staticcheck // http2.Server is deprecated; kept for backward compatibility. } // NewRouter initializes a new grpc http router @@ -32,7 +32,7 @@ func NewRouter(backends ...Backend) router.Router { } r := &grpcRouter{ - h2Server: &http2.Server{}, + h2Server: &http2.Server{}, //nolint:staticcheck // http2.Server is deprecated; kept for backward compatibility. grpcServer: grpc.NewServer(opts...), } for _, b := range backends { diff --git a/api/server/router/grpc/grpc_routes.go b/api/server/router/grpc/grpc_routes.go index 1fe0da472f..1417186c44 100644 --- a/api/server/router/grpc/grpc_routes.go +++ b/api/server/router/grpc/grpc_routes.go @@ -38,8 +38,12 @@ func (gr *grpcRouter) serveGRPC(ctx context.Context, w http.ResponseWriter, r *h conn.Write([]byte{}) resp.Write(conn) - // https://godoc.org/golang.org/x/net/http2#Server.ServeConn - // TODO: is it a problem that conn has already been written to? - gr.h2Server.ServeConn(conn, &http2.ServeConnOpts{Handler: gr.grpcServer}) + // Keep using the deprecated http2.Server for compatibility with clients + // using the /grpc endpoint, which performs an HTTP/1.1 Upgrade: h2c + // handshake. net/http's unencrypted HTTP/2 support uses HTTP/2 with prior + // knowledge and does not support Upgrade: h2c. + gr.h2Server.ServeConn(conn, &http2.ServeConnOpts{ //nolint:staticcheck // http2.ServeConn and http2.ServeConnOpts are deprecated. + Handler: gr.grpcServer, + }) return nil }