Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set the max header bytes param configurable #721

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ type ServiceConfig struct {
// after reading the headers and the Handler can decide what
// is considered too slow for the body.
ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout"`
// MaxHeaderBytes controls the maximum number of bytes the
// server will read parsing the request header's keys and
// values, including the request line. It does not limit the
// size of the request body.
// If zero, DefaultMaxHeaderBytes (1MB) is used.
MaxHeaderBytes int `mapstructure:"max_header_bytes"`

// DisableKeepAlives, if true, prevents re-use of TCP connections
// between different HTTP requests.
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestConfig_init(t *testing.T) {
t.Error(err.Error())
}

if hash != "GdZTJtCn9ZHj3iBR1ZxmZL65HjbTCU8HhbDG8YWudAo=" {
if hash != "dEnC/Sn/mHYtt5vj+DkI0Ib22D/1liL8zx/WHpT2ajY=" {
t.Errorf("unexpected hash: %s", hash)
}
}
Expand Down
2 changes: 2 additions & 0 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ type parseableServiceConfig struct {
WriteTimeout string `json:"write_timeout"`
IdleTimeout string `json:"idle_timeout"`
ReadHeaderTimeout string `json:"read_header_timeout"`
MaxHeaderBytes int `json:"max_header_bytes"`
DisableKeepAlives bool `json:"disable_keep_alives"`
DisableCompression bool `json:"disable_compression"`
DisableStrictREST bool `json:"disable_rest"`
Expand Down Expand Up @@ -181,6 +182,7 @@ func (p *parseableServiceConfig) normalize() ServiceConfig {
WriteTimeout: parseDuration(p.WriteTimeout),
IdleTimeout: parseDuration(p.IdleTimeout),
ReadHeaderTimeout: parseDuration(p.ReadHeaderTimeout),
MaxHeaderBytes: p.MaxHeaderBytes,
DisableKeepAlives: p.DisableKeepAlives,
DisableCompression: p.DisableCompression,
DisableStrictREST: p.DisableStrictREST,
Expand Down
4 changes: 4 additions & 0 deletions config/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestNewParser_ok(t *testing.T) {
"port": 8080,
"cache_ttl": "3600s",
"timeout": "3s",
"max_header_bytes": 10000,
"tls": {
"public_key": "cert.pem",
"private_key": "key.pem"
Expand Down Expand Up @@ -108,6 +109,9 @@ func TestNewParser_ok(t *testing.T) {
if err != nil {
t.Error("Unexpected error. Got", err.Error())
}
if serviceConfig.MaxHeaderBytes != 10000 {
t.Errorf("unexpected max_header_bytes value. have %d, want 10000", serviceConfig.MaxHeaderBytes)
}
testExtraConfig(serviceConfig.ExtraConfig, t)

if endpoints := len(serviceConfig.Endpoints); endpoints != 3 {
Expand Down
1 change: 1 addition & 0 deletions transport/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func NewServerWithLogger(cfg config.ServiceConfig, handler http.Handler, logger
ReadHeaderTimeout: cfg.ReadHeaderTimeout,
IdleTimeout: cfg.IdleTimeout,
TLSConfig: ParseTLSConfigWithLogger(cfg.TLS, logger),
MaxHeaderBytes: cfg.MaxHeaderBytes,
}
}

Expand Down
Loading