Implement HTTP2 HPACK table size options
This commit is contained in:
parent
5d830477b7
commit
0b7f0b4042
7 changed files with 115 additions and 8 deletions
|
|
@ -631,6 +631,12 @@ func newHTTPServer(ctx context.Context, ln net.Listener, configuration *static.E
|
|||
if configuration.HTTP2.MaxConcurrentStreams < 0 {
|
||||
return nil, errors.New("max concurrent streams value must be greater than or equal to zero")
|
||||
}
|
||||
if configuration.HTTP2.MaxDecoderHeaderTableSize < 0 {
|
||||
return nil, errors.New("max decoder header table size value must be greater than or equal to zero")
|
||||
}
|
||||
if configuration.HTTP2.MaxEncoderHeaderTableSize < 0 {
|
||||
return nil, errors.New("max encoder header table size value must be greater than or equal to zero")
|
||||
}
|
||||
|
||||
httpSwitcher := middlewares.NewHandlerSwitcher(http.NotFoundHandler())
|
||||
|
||||
|
|
@ -688,7 +694,9 @@ func newHTTPServer(ctx context.Context, ln net.Listener, configuration *static.E
|
|||
IdleTimeout: time.Duration(configuration.Transport.RespondingTimeouts.IdleTimeout),
|
||||
MaxHeaderBytes: configuration.HTTP.MaxHeaderBytes,
|
||||
HTTP2: &http.HTTP2Config{
|
||||
MaxConcurrentStreams: int(configuration.HTTP2.MaxConcurrentStreams),
|
||||
MaxConcurrentStreams: int(configuration.HTTP2.MaxConcurrentStreams),
|
||||
MaxDecoderHeaderTableSize: int(configuration.HTTP2.MaxDecoderHeaderTableSize),
|
||||
MaxEncoderHeaderTableSize: int(configuration.HTTP2.MaxEncoderHeaderTableSize),
|
||||
},
|
||||
}
|
||||
if debugConnection || (configuration.Transport != nil && (configuration.Transport.KeepAliveMaxTime > 0 || configuration.Transport.KeepAliveMaxRequests > 0)) {
|
||||
|
|
|
|||
|
|
@ -648,3 +648,34 @@ func TestPathOperations(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTP2Config(t *testing.T) {
|
||||
expectedMaxConcurrentStreams := 42
|
||||
expectedEncoderTableSize := 128
|
||||
expectedDecoderTableSize := 256
|
||||
|
||||
// Create a listener for the server.
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
_ = ln.Close()
|
||||
})
|
||||
|
||||
// Define the server configuration.
|
||||
configuration := &static.EntryPoint{}
|
||||
configuration.SetDefaults()
|
||||
configuration.HTTP2.MaxConcurrentStreams = int32(expectedMaxConcurrentStreams)
|
||||
configuration.HTTP2.MaxEncoderHeaderTableSize = int32(expectedEncoderTableSize)
|
||||
configuration.HTTP2.MaxDecoderHeaderTableSize = int32(expectedDecoderTableSize)
|
||||
|
||||
// Create the HTTP server using newHTTPServer.
|
||||
server, err := newHTTPServer(t.Context(), ln, configuration, false, requestdecorator.New(nil))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Get the underlying HTTP Server.
|
||||
httpServer := server.Server.(*http.Server)
|
||||
|
||||
assert.Equal(t, expectedMaxConcurrentStreams, httpServer.HTTP2.MaxConcurrentStreams)
|
||||
assert.Equal(t, expectedEncoderTableSize, httpServer.HTTP2.MaxEncoderHeaderTableSize)
|
||||
assert.Equal(t, expectedDecoderTableSize, httpServer.HTTP2.MaxDecoderHeaderTableSize)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue