Skip to content

Commit

Permalink
refactor: MaxHeaderBytes -> MaxRequestHeaderBytes
Browse files Browse the repository at this point in the history
Rename the config property in preparation for the new response header
limit. The YAML property retains its name to stay compatible with any
existing configurations.
  • Loading branch information
maxmoehl authored and ameowlia committed Nov 18, 2024
1 parent e9ba2e1 commit 35e4728
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ type Config struct {
DisableKeepAlives bool `yaml:"disable_keep_alives"`
MaxIdleConns int `yaml:"max_idle_conns,omitempty"`
MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host,omitempty"`
MaxHeaderBytes int `yaml:"max_header_bytes"`
MaxRequestHeaderBytes int `yaml:"max_request_header_bytes"`
KeepAlive100ContinueRequests bool `yaml:"keep_alive_100_continue_requests"`

HTTPRewrite HTTPRewrite `yaml:"http_rewrite,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ status:
})
It("sets MaxHeaderBytes", func() {
var b = []byte(`
max_header_bytes: 10
max_request_header_bytes: 10
`)

err := config.Initialize(b)
Expect(err).ToNot(HaveOccurred())

Expect(config.MaxHeaderBytes).To(Equal(10))
Expect(config.MaxRequestHeaderBytes).To(Equal(10))
})

It("sets prometheus endpoint config", func() {
Expand Down
2 changes: 1 addition & 1 deletion handlers/max_request_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ONE_MB = 1024 * 1024 // bytes * kb
// NewAccessLog creates a new handler that handles logging requests to the
// access log
func NewMaxRequestSize(cfg *config.Config, logger *slog.Logger) *MaxRequestSize {
maxSize := cfg.MaxHeaderBytes
maxSize := cfg.MaxRequestHeaderBytes

if maxSize < 1 {
maxSize = ONE_MB
Expand Down
10 changes: 5 additions & 5 deletions handlers/max_request_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var _ = Describe("MaxRequestSize", func() {

BeforeEach(func() {
cfg = &config.Config{
MaxHeaderBytes: 89,
MaxRequestHeaderBytes: 89,
LoadBalance: config.LOAD_BALANCE_RR,
StickySessionCookieNames: config.StringSet{"blarg": struct{}{}},
}
Expand Down Expand Up @@ -216,7 +216,7 @@ var _ = Describe("MaxRequestSize", func() {
Describe("NewMaxRequestSize()", func() {
Context("when using a custom MaxHeaderBytes", func() {
BeforeEach(func() {
cfg.MaxHeaderBytes = 1234
cfg.MaxRequestHeaderBytes = 1234
})
It("returns a new requestSizeHandler using the provided size", func() {
Expect(rh.MaxSize).To(Equal(1234))
Expand All @@ -225,15 +225,15 @@ var _ = Describe("MaxRequestSize", func() {

Context("when using a negative MaxHeaderBytes", func() {
BeforeEach(func() {
cfg.MaxHeaderBytes = -1
cfg.MaxRequestHeaderBytes = -1
})
It("defaults to 1mb", func() {
Expect(rh.MaxSize).To(Equal(1024 * 1024))
})
})
Context("when using a zero-value MaxHeaderBytes", func() {
BeforeEach(func() {
cfg.MaxHeaderBytes = 0
cfg.MaxRequestHeaderBytes = 0
})
It("defaults to 1mb", func() {
Expect(rh.MaxSize).To(Equal(1024 * 1024))
Expand All @@ -242,7 +242,7 @@ var _ = Describe("MaxRequestSize", func() {

Context("when using a >1mb MaxHeaderBytes", func() {
BeforeEach(func() {
cfg.MaxHeaderBytes = handlers.ONE_MB * 2
cfg.MaxRequestHeaderBytes = handlers.ONE_MB * 2
})
It("defaults to 1mb if the provided size", func() {
Expect(rh.MaxSize).To(Equal(1024 * 1024))
Expand Down
2 changes: 1 addition & 1 deletion integration/common_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func NewTestState() *testState {
}
cfg.OAuth.TokenEndpoint, cfg.OAuth.Port = hostnameAndPort(oauthServer.Addr())

cfg.MaxHeaderBytes = 48 * 1024 //1kb
cfg.MaxRequestHeaderBytes = 48 * 1024 //1kb

return &testState{
cfg: cfg,
Expand Down
2 changes: 1 addition & 1 deletion integration/large_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = Describe("Large requests", func() {
testState = NewTestState()
testState.EnableAccessLog()
testState.EnableMetron()
testState.cfg.MaxHeaderBytes = 1 * 1024 // 1kb
testState.cfg.MaxRequestHeaderBytes = 1 * 1024 // 1kb
testState.StartGorouterOrFail()

appURL = "echo-app." + test_util.LocalhostDNS
Expand Down

0 comments on commit 35e4728

Please sign in to comment.