Skip to content

Commit

Permalink
server: add ServerOption HeaderTableSize (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoZhonghua authored and dfawley committed Oct 3, 2019
1 parent 3778847 commit fb2e5cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/transport/http2_server.go
Expand Up @@ -174,6 +174,12 @@ func newHTTP2Server(conn net.Conn, config *ServerConfig) (_ ServerTransport, err
Val: *config.MaxHeaderListSize,
})
}
if config.HeaderTableSize != nil {
isettings = append(isettings, http2.Setting{
ID: http2.SettingHeaderTableSize,
Val: *config.HeaderTableSize,
})
}
if err := framer.fr.WriteSettings(isettings...); err != nil {
return nil, connectionErrorf(false, err, "transport: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/transport/transport.go
Expand Up @@ -525,6 +525,7 @@ type ServerConfig struct {
ReadBufferSize int
ChannelzParentID int64
MaxHeaderListSize *uint32
HeaderTableSize *uint32
}

// NewServerTransport creates a ServerTransport with conn or non-nil error
Expand Down
12 changes: 12 additions & 0 deletions server.go
Expand Up @@ -130,6 +130,7 @@ type serverOptions struct {
readBufferSize int
connectionTimeout time.Duration
maxHeaderListSize *uint32
headerTableSize *uint32
}

var defaultServerOptions = serverOptions{
Expand Down Expand Up @@ -377,6 +378,16 @@ func MaxHeaderListSize(s uint32) ServerOption {
})
}

// HeaderTableSize returns a ServerOption that sets the size of dynamic
// header table for stream.
//
// This API is EXPERIMENTAL.
func HeaderTableSize(s uint32) ServerOption {
return newFuncServerOption(func(o *serverOptions) {
o.headerTableSize = &s
})
}

// NewServer creates a gRPC server which has no service registered and has not
// started to accept requests yet.
func NewServer(opt ...ServerOption) *Server {
Expand Down Expand Up @@ -686,6 +697,7 @@ func (s *Server) newHTTP2Transport(c net.Conn, authInfo credentials.AuthInfo) tr
ReadBufferSize: s.opts.readBufferSize,
ChannelzParentID: s.channelzID,
MaxHeaderListSize: s.opts.maxHeaderListSize,
HeaderTableSize: s.opts.headerTableSize,
}
st, err := transport.NewServerTransport("http2", c, config)
if err != nil {
Expand Down

0 comments on commit fb2e5cd

Please sign in to comment.