Skip to content

Commit bb2fe56

Browse files
committed
fix: replace deprecated h2c.NewHandler with http.Server.Protocols
golangci-lint flagged SA1019 against golang.org/x/net/http2/h2c, which upstream marked deprecated in favor of the http.Server.Protocols field introduced in Go 1.24. - cmds/dutagent/dutagent.go, cmds/exp/dutserver/dutserver.go: drop the h2c.NewHandler + http2.Server wrapper; configure http.Server with Protocols = {HTTP1, UnencryptedHTTP2} for the same behavior. Signed-off-by: Fabian Wienand <fabian.wienand@blindspot.software>
1 parent cf3d35b commit bb2fe56

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

cmds/dutagent/dutagent.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/BlindspotSoftware/dutctl/pkg/dut"
2828
"github.com/BlindspotSoftware/dutctl/protobuf/gen/dutctl/v1/dutctlv1connect"
2929
"golang.org/x/net/http2"
30-
"golang.org/x/net/http2/h2c"
3130
"gopkg.in/yaml.v3"
3231

3332
pb "github.com/BlindspotSoftware/dutctl/protobuf/gen/dutctl/v1"
@@ -166,12 +165,20 @@ func (agt *agent) startRPCService() error {
166165
path, handler := dutctlv1connect.NewDeviceServiceHandler(service)
167166
mux.Handle(path, handler)
168167

168+
// Serve HTTP/2 without TLS via http.Server.Protocols (replaces the
169+
// deprecated golang.org/x/net/http2/h2c handler).
170+
protocols := new(http.Protocols)
171+
protocols.SetHTTP1(true)
172+
protocols.SetUnencryptedHTTP2(true)
173+
169174
//nolint:gosec
170-
return http.ListenAndServe(
171-
agt.address,
172-
// Use h2c so we can serve HTTP/2 without TLS.
173-
h2c.NewHandler(mux, &http2.Server{}),
174-
)
175+
srv := &http.Server{
176+
Addr: agt.address,
177+
Handler: mux,
178+
Protocols: protocols,
179+
}
180+
181+
return srv.ListenAndServe()
175182
}
176183

177184
func (agt *agent) registerWithServer() error {

cmds/exp/dutserver/dutserver.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"syscall"
1717

1818
"github.com/BlindspotSoftware/dutctl/protobuf/gen/dutctl/v1/dutctlv1connect"
19-
"golang.org/x/net/http2"
20-
"golang.org/x/net/http2/h2c"
2119
)
2220

2321
const (
@@ -94,12 +92,20 @@ func (svr *server) startRPCService() error {
9492
path, handler = dutctlv1connect.NewRelayServiceHandler(service)
9593
mux.Handle(path, handler)
9694

95+
// Serve HTTP/2 without TLS via http.Server.Protocols (replaces the
96+
// deprecated golang.org/x/net/http2/h2c handler).
97+
protocols := new(http.Protocols)
98+
protocols.SetHTTP1(true)
99+
protocols.SetUnencryptedHTTP2(true)
100+
97101
//nolint:gosec
98-
return http.ListenAndServe(
99-
svr.address,
100-
// Use h2c so we can serve HTTP/2 without TLS.
101-
h2c.NewHandler(mux, &http2.Server{}),
102-
)
102+
srv := &http.Server{
103+
Addr: svr.address,
104+
Handler: mux,
105+
Protocols: protocols,
106+
}
107+
108+
return srv.ListenAndServe()
103109
}
104110

105111
// start orchestrates the dutagent execution.

0 commit comments

Comments
 (0)