From f2078620ee331682e028d9b217f14fb09020811d Mon Sep 17 00:00:00 2001 From: "Nicholas S. Husin" Date: Wed, 21 Jan 2026 15:35:08 -0500 Subject: [PATCH] http2: allow prioritization to be disabled using DisableClientPriority field As part of adding support for HTTP/2 stream prioritization, a DisableClientPriority field will be added to http.Server to allow users to completely disable client prioritization if desired. When DisableClientPriority is set to true, HTTP/2 server will revert back to the old behavior where streams are processed in a round-robin manner. For golang/go#75500 Change-Id: Ida083b3ac17a953e5ddb3ad7ab8a81f9cde2bfc1 Reviewed-on: https://go-review.googlesource.com/c/net/+/737521 Reviewed-by: Damien Neil Reviewed-by: Nicholas Husin LUCI-TryBot-Result: Go LUCI --- http2/client_priority_go126.go | 20 ++++++++++++++++++++ http2/client_priority_go127.go | 13 +++++++++++++ http2/server.go | 7 +++++-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 http2/client_priority_go126.go create mode 100644 http2/client_priority_go127.go diff --git a/http2/client_priority_go126.go b/http2/client_priority_go126.go new file mode 100644 index 00000000..80af000b --- /dev/null +++ b/http2/client_priority_go126.go @@ -0,0 +1,20 @@ +// Copyright 2026 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !go1.27 + +package http2 + +import "net/http" + +// Support for go.dev/issue/75500 is added in Go 1.27. In case anyone uses +// x/net with versions before Go 1.27, we return true here so that their write +// scheduler will still be the round-robin write scheduler rather than the RFC +// 9218 write scheduler. That way, older users of Go will not see a sudden +// change of behavior just from importing x/net. +// +// TODO(nsh): remove this file after x/net go.mod is at Go 1.27. +func clientPriorityDisabled(_ *http.Server) bool { + return true +} diff --git a/http2/client_priority_go127.go b/http2/client_priority_go127.go new file mode 100644 index 00000000..817d01b0 --- /dev/null +++ b/http2/client_priority_go127.go @@ -0,0 +1,13 @@ +// Copyright 2026 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build go1.27 + +package http2 + +import "net/http" + +func clientPriorityDisabled(s *http.Server) bool { + return s.DisableClientPriority +} diff --git a/http2/server.go b/http2/server.go index fab077b1..7ef807f7 100644 --- a/http2/server.go +++ b/http2/server.go @@ -472,10 +472,13 @@ func (s *Server) serveConn(c net.Conn, opts *ServeConnOpts, newf func(*serverCon sc.conn.SetWriteDeadline(time.Time{}) } - if s.NewWriteScheduler != nil { + switch { + case s.NewWriteScheduler != nil: sc.writeSched = s.NewWriteScheduler() - } else { + case clientPriorityDisabled(http1srv): sc.writeSched = newRoundRobinWriteScheduler() + default: + sc.writeSched = newPriorityWriteSchedulerRFC9218() } // These start at the RFC-specified defaults. If there is a higher