Skip to content

Commit ed6b1e3

Browse files
authored
When reference server is in HTTP 1.1 mode, don't allow negotiating HTTP/2 via TLS (#856)
Some clients may not have the direct ability to _disable_ negotiating HTTP/2 if the server advertises its support during ALPN step of TLS handshake. So to prevent such clients from using HTTP/2, if HTTP 1.1. is the intent, we disable HTTP/2 in the reference server. (Sadly, we can't also disable HTTP 1.1 when HTTP/2 is the intent since Go's `net/http` doesn't provide a way to do that 🤷.)
1 parent f527afc commit ed6b1e3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

internal/app/referenceserver/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ func newH1Server(handler http.Handler, listenAddr string, tlsConf *tls.Config) (
321321
TLSConfig: tlsConf,
322322
ReadHeaderTimeout: 5 * time.Second,
323323
ErrorLog: nopLogger(),
324+
// We disable automatic HTTP/2 support by setting this to non-nil
325+
TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){},
324326
}
325327
lis, err := net.Listen("tcp", listenAddr)
326328
if err != nil {
@@ -340,6 +342,9 @@ func newH2Server(handler http.Handler, listenAddr string, tlsConf *tls.Config) (
340342
TLSConfig: tlsConf,
341343
ReadHeaderTimeout: 5 * time.Second,
342344
ErrorLog: nopLogger(),
345+
// There's no way to disable HTTP 1.1 support and *require* HTTP/2. So
346+
// if the client says it supports HTTP/2, we rely on it negotiating
347+
// that during ALPN of TLS handshake instead of HTTP 1.1. ¯\_(ツ)_/¯
343348
}
344349
lis, err := net.Listen("tcp", listenAddr)
345350
if err != nil {

0 commit comments

Comments
 (0)