@@ -172,33 +172,31 @@ func (s *SecureServingInfo) Serve(handler http.Handler, shutdownTimeout time.Dur
172
172
ReadHeaderTimeout : 32 * time .Second , // just shy of requestTimeoutUpperBound
173
173
}
174
174
175
- // At least 99% of serialized resources in surveyed clusters were smaller than 256kb.
176
- // This should be big enough to accommodate most API POST requests in a single frame,
177
- // and small enough to allow a per connection buffer of this size multiplied by `MaxConcurrentStreams`.
178
- const resourceBody99Percentile = 256 * 1024
179
-
180
- http2Options := & http2.Server {
181
- IdleTimeout : 90 * time .Second , // matches http.DefaultTransport keep-alive timeout
182
- }
183
-
184
- // shrink the per-stream buffer and max framesize from the 1MB default while still accommodating most API POST requests in a single frame
185
- http2Options .MaxUploadBufferPerStream = resourceBody99Percentile
186
- http2Options .MaxReadFrameSize = resourceBody99Percentile
187
-
188
- // use the overridden concurrent streams setting or make the default of 250 explicit so we can size MaxUploadBufferPerConnection appropriately
189
- if s .HTTP2MaxStreamsPerConnection > 0 {
190
- http2Options .MaxConcurrentStreams = uint32 (s .HTTP2MaxStreamsPerConnection )
191
- } else {
192
- // match http2.initialMaxConcurrentStreams used by clients
193
- // this makes it so that a malicious client can only open 400 streams before we forcibly close the connection
194
- // https://github.com/golang/net/commit/b225e7ca6dde1ef5a5ae5ce922861bda011cfabd
195
- http2Options .MaxConcurrentStreams = 100
196
- }
175
+ if ! s .DisableHTTP2 {
176
+ // At least 99% of serialized resources in surveyed clusters were smaller than 256kb.
177
+ // This should be big enough to accommodate most API POST requests in a single frame,
178
+ // and small enough to allow a per connection buffer of this size multiplied by `MaxConcurrentStreams`.
179
+ const resourceBody99Percentile = 256 * 1024
180
+
181
+ http2Options := & http2.Server {
182
+ IdleTimeout : 90 * time .Second , // matches http.DefaultTransport keep-alive timeout
183
+ // shrink the per-stream buffer and max framesize from the 1MB default while still accommodating most API POST requests in a single frame
184
+ MaxUploadBufferPerStream : resourceBody99Percentile ,
185
+ MaxReadFrameSize : resourceBody99Percentile ,
186
+ }
197
187
198
- // increase the connection buffer size from the 1MB default to handle the specified number of concurrent streams
199
- http2Options .MaxUploadBufferPerConnection = http2Options .MaxUploadBufferPerStream * int32 (http2Options .MaxConcurrentStreams )
188
+ // use the overridden concurrent streams setting or make the default of 250 explicit so we can size MaxUploadBufferPerConnection appropriately
189
+ if s .HTTP2MaxStreamsPerConnection > 0 {
190
+ http2Options .MaxConcurrentStreams = uint32 (s .HTTP2MaxStreamsPerConnection )
191
+ } else {
192
+ // match http2.initialMaxConcurrentStreams used by clients
193
+ // this makes it so that a malicious client can only open 400 streams before we forcibly close the connection
194
+ // https://github.com/golang/net/commit/b225e7ca6dde1ef5a5ae5ce922861bda011cfabd
195
+ http2Options .MaxConcurrentStreams = 100
196
+ }
200
197
201
- if ! s .DisableHTTP2 {
198
+ // increase the connection buffer size from the 1MB default to handle the specified number of concurrent streams
199
+ http2Options .MaxUploadBufferPerConnection = http2Options .MaxUploadBufferPerStream * int32 (http2Options .MaxConcurrentStreams )
202
200
// apply settings to the server
203
201
if err := http2 .ConfigureServer (secureServer , http2Options ); err != nil {
204
202
return nil , nil , fmt .Errorf ("error configuring http2: %v" , err )
0 commit comments