api/server/router/grpc: fix linting for deprecated http2 code

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit c47560390b)

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 <csnider@mirantis.com>
This commit is contained in:
Sebastiaan van Stijn authored and Cory Snider committed 2026-11-03 21:02:38 -05:00
1 parent 5f676ff944
commit 2fa7c43d31
2 files changed
+9 -5

No files matched your search

+2 -2
View File
@@ -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 {
+7 -3
View File
@@ -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
}