Skip to content

Commit f3ca034

Browse files
neildgopherbot
authored andcommitted
http2: deprecate Transport and Server
Fixes golang/go#78064 Change-Id: Ia8f5c109b4594ef5a4fca1eacfc0f2da6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/net/+/819740 Auto-Submit: Damien Neil <[email protected]> Reviewed-by: Nicholas Husin <[email protected]> Reviewed-by: Nicholas Husin <[email protected]> LUCI-TryBot-Result: [email protected] <[email protected]>
1 parent a375228 commit f3ca034

5 files changed

Lines changed: 150 additions & 3 deletions

File tree

‎http2/example_test.go‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2026 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package http2
6+
7+
import "net/http"
8+
9+
// To configure an [http.Transport] to use HTTP/2,
10+
// set the [http.Transport.Protocols] field.
11+
func ExampleConfigureTransport() {
12+
tr := &http.Transport{}
13+
tr.Protocols = new(http.Protocols)
14+
tr.Protocols.SetHTTP1(true) // enable HTTP/1
15+
tr.Protocols.SetHTTP2(true) // enable HTTP/2
16+
}
17+
18+
// To configure an [http.Transport] to use HTTP/2,
19+
// set the [http.Transport.Protocols] field.
20+
func ExampleConfigureTransports() {
21+
tr := &http.Transport{}
22+
tr.Protocols = new(http.Protocols)
23+
tr.Protocols.SetHTTP1(true) // enable HTTP/1
24+
tr.Protocols.SetHTTP2(true) // enable HTTP/2
25+
}
26+
27+
// To configure an [http.Server] to use HTTP/2,
28+
// set the [http.Server.Protocols] field.
29+
func ExampleConfigureServer() {
30+
server := &http.Server{}
31+
server.Protocols = new(http.Protocols)
32+
server.Protocols.SetHTTP1(true) // enable HTTP/1
33+
server.Protocols.SetHTTP2(true) // enable HTTP/2
34+
}

‎http2/server_common.go‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
//
2626
// https://golang.org/pkg/net/http/#ResponseWriter
2727
// https://golang.org/pkg/net/http/#example_ResponseWriter_trailers
28+
//
29+
// Deprecated: Use [http.TrailerPrefix] instead.
2830
const TrailerPrefix = "Trailer:"
2931

3032
// Push errors.
@@ -38,16 +40,22 @@ var (
3840
// The configuration conf may be nil.
3941
//
4042
// ConfigureServer must be called before s begins serving.
43+
//
44+
// Deprecated: Set [http.Server.Protocols] instead.
4145
func ConfigureServer(s *http.Server, conf *Server) error {
4246
return configureServer(s, conf)
4347
}
4448

4549
// Server is an HTTP/2 server.
50+
//
51+
// Deprecated: Use [http.Server] instead.
4652
type Server struct {
4753
// MaxHandlers limits the number of http.Handler ServeHTTP goroutines
4854
// which may run at a time over all connections.
4955
// Negative or zero no limit.
5056
// TODO: implement
57+
//
58+
// Deprecated: This field has never had any effect.
5159
MaxHandlers int
5260

5361
// MaxConcurrentStreams optionally specifies the number of
@@ -56,64 +64,96 @@ type Server struct {
5664
// which may be active globally, which is MaxHandlers.
5765
// If zero, MaxConcurrentStreams defaults to at least 100, per
5866
// the HTTP/2 spec's recommendations.
67+
//
68+
// Deprecated: Use [http.Server.HTTP2] and
69+
// [http.HTTP2Config.MaxConcurrentStreams] instead.
5970
MaxConcurrentStreams uint32
6071

6172
// MaxDecoderHeaderTableSize optionally specifies the http2
6273
// SETTINGS_HEADER_TABLE_SIZE to send in the initial settings frame. It
6374
// informs the remote endpoint of the maximum size of the header compression
6475
// table used to decode header blocks, in octets. If zero, the default value
6576
// of 4096 is used.
77+
//
78+
// Deprecated: Use [http.Server.HTTP2] and
79+
// [http.HTTP2Config.MaxDecoderHeaderTableSize] instead.
6680
MaxDecoderHeaderTableSize uint32
6781

6882
// MaxEncoderHeaderTableSize optionally specifies an upper limit for the
6983
// header compression table used for encoding request headers. Received
7084
// SETTINGS_HEADER_TABLE_SIZE settings are capped at this limit. If zero,
7185
// the default value of 4096 is used.
86+
//
87+
// Deprecated: Use [http.Server.HTTP2] and
88+
// [http.HTTP2Config.MaxEncoderHeaderTableSize] instead.
7289
MaxEncoderHeaderTableSize uint32
7390

7491
// MaxReadFrameSize optionally specifies the largest frame
7592
// this server is willing to read. A valid value is between
7693
// 16k and 16M, inclusive. If zero or otherwise invalid, a
7794
// default value is used.
95+
//
96+
// Deprecated: Use [http.Server.HTTP2] and
97+
// [http.HTTP2Config.MaxReadFrameSize] instead.
7898
MaxReadFrameSize uint32
7999

80100
// PermitProhibitedCipherSuites, if true, permits the use of
81101
// cipher suites prohibited by the HTTP/2 spec.
102+
//
103+
// Deprecated: Use [http.Server.HTTP2] and
104+
// [http.HTTP2Config.PermitProhibitedCipherSuites] instead.
82105
PermitProhibitedCipherSuites bool
83106

84107
// IdleTimeout specifies how long until idle clients should be
85108
// closed with a GOAWAY frame. PING frames are not considered
86109
// activity for the purposes of IdleTimeout.
87110
// If zero or negative, there is no timeout.
111+
//
112+
// Deprecated: Use [http.Server.IdleTimeout] instead.
88113
IdleTimeout time.Duration
89114

90115
// ReadIdleTimeout is the timeout after which a health check using a ping
91116
// frame will be carried out if no frame is received on the connection.
92117
// If zero, no health check is performed.
118+
//
119+
// Deprecated: Use [http.Server.HTTP2] and
120+
// [http.HTTP2Config.SendPingTimeout] instead.
93121
ReadIdleTimeout time.Duration
94122

95123
// PingTimeout is the timeout after which the connection will be closed
96124
// if a response to a ping is not received.
97125
// If zero, a default of 15 seconds is used.
126+
//
127+
// Deprecated: Use [http.Server.HTTP2] and
128+
// [http.HTTP2Config.PingTimeout] instead.
98129
PingTimeout time.Duration
99130

100131
// WriteByteTimeout is the timeout after which a connection will be
101132
// closed if no data can be written to it. The timeout begins when data is
102133
// available to write, and is extended whenever any bytes are written.
103134
// If zero or negative, there is no timeout.
135+
//
136+
// Deprecated: Use [http.Server.HTTP2] and
137+
// [http.HTTP2Config.WriteByteTimeout] instead.
104138
WriteByteTimeout time.Duration
105139

106140
// MaxUploadBufferPerConnection is the size of the initial flow
107141
// control window for each connections. The HTTP/2 spec does not
108142
// allow this to be smaller than 65535 or larger than 2^32-1.
109143
// If the value is outside this range, a default value will be
110144
// used instead.
145+
//
146+
// Deprecated: Use [http.Server.HTTP2] and
147+
// [http.HTTP2Config.MaxReceiveBufferPerConnection] instead.
111148
MaxUploadBufferPerConnection int32
112149

113150
// MaxUploadBufferPerStream is the size of the initial flow control
114151
// window for each stream. The HTTP/2 spec does not allow this to
115152
// be larger than 2^32-1. If the value is zero or larger than the
116153
// maximum, a default value will be used instead.
154+
//
155+
// Deprecated: Use [http.Server.HTTP2] and
156+
// [http.HTTP2Config.MaxReceiveBufferPerStream] instead.
117157
MaxUploadBufferPerStream int32
118158

119159
// NewWriteScheduler constructs a write scheduler for a connection.
@@ -126,6 +166,9 @@ type Server struct {
126166
// It's intended to increment a metric for monitoring, such
127167
// as an expvar or Prometheus metric.
128168
// The errType consists of only ASCII word characters.
169+
//
170+
// Deprecated: Use [http.Server.HTTP2] and
171+
// [http.HTTP2Config.CountError] instead.
129172
CountError func(errType string)
130173

131174
// Internal state. This is a pointer (rather than embedded directly)
@@ -135,6 +178,8 @@ type Server struct {
135178
}
136179

137180
// ServeConnOpts are options for the Server.ServeConn method.
181+
//
182+
// Deprecated: ServeConnOpts is deprecated.
138183
type ServeConnOpts struct {
139184
// Context is the base context to use.
140185
// If nil, context.Background is used.
@@ -178,6 +223,8 @@ type ServeConnOpts struct {
178223
// implemented in terms of providing a suitably-behaving net.Conn.
179224
//
180225
// The opts parameter is optional. If nil, default values are used.
226+
//
227+
// Deprecated: Use [http.Server.Serve] or [http.Server.ServeTLS] instead.
181228
func (s *Server) ServeConn(c net.Conn, opts *ServeConnOpts) {
182229
if opts == nil {
183230
opts = &ServeConnOpts{}

‎http2/transport.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ func (t *Transport) initConnPool() {
184184

185185
// ClientConn is the state of a single HTTP/2 client connection to an
186186
// HTTP/2 server.
187+
//
188+
// Deprecated: Use [http.ClientConn] instead.
187189
type ClientConn struct {
188190
t *Transport
189191
tconn net.Conn // usually *tls.Conn, except specialized impls

0 commit comments

Comments
 (0)