Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling h2c in httpserver.Run #2119

Merged
merged 2 commits into from
May 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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