Skip to content

Commit

Permalink
Allow disabling h2c in httpserver.Run (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkwarren committed May 24, 2023
1 parent 5518eb8 commit fb4875e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion private/pkg/transport/http/httpserver/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type runner struct {
readHeaderTimeout time.Duration
tlsConfig *tls.Config
walkFunc chi.WalkFunc
disableH2C bool
}

// RunOption is an option for a new Run.
Expand Down Expand Up @@ -87,6 +88,13 @@ func RunWithWalkFunc(walkFunc chi.WalkFunc) RunOption {
}
}

// RunWithoutH2C disables use of H2C (used when RunWithTLSConfig is not called).
func RunWithoutH2C() RunOption {
return func(runner *runner) {
runner.disableH2C = true
}
}

// Run will start a HTTP server listening on the provided listener and
// serving the provided handler. This call is blocking and the run
// is cancelled when the input context is cancelled, the listener is
Expand Down Expand Up @@ -117,7 +125,7 @@ func Run(
ErrorLog: stdLogger,
TLSConfig: s.tlsConfig,
}
if s.tlsConfig == nil {
if s.tlsConfig == nil && !s.disableH2C {
httpServer.Handler = h2c.NewHandler(handler, &http2.Server{
IdleTimeout: DefaultIdleTimeout,
})
Expand Down

0 comments on commit fb4875e

Please sign in to comment.