Skip to content

Commit 593e8fe

Browse files
committed
server: offer "http/1.1" and "h2" via ALPN
As per the gRPC spec, recent clients require that we offer "h2". So, offer both "http/1.1" and "h2", preferring "http/1.1". Regular HTTP clients will negotiate http/1.1 (h2 is not supported), and gRPC clients (which don't offer http/1.1) will negotiate h2.
1 parent 155aa5f commit 593e8fe

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

server/server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ func New(
108108
grpc.MaxRecvMsgSize(int(maxGRPCRecvSize)),
109109
),
110110
}
111+
112+
// gRPC v1.67+ requires that we advertise "h2" via ALPN.
113+
// However we only offer HTTP/2 for gRPC connections,
114+
// so pick it only if "http/1.1" isn't offered
115+
// (which is true only of gRPC clients).
116+
if serverTLS != nil {
117+
serverTLS.NextProtos = []string{"http/1.1", "h2"}
118+
}
119+
111120
if wrapListener != nil {
112121
if listener, err = wrapListener(listener, serverTLS); err != nil {
113122
return nil, fmt.Errorf("failed to wrap listener: %w", err)

0 commit comments

Comments
 (0)