Skip to content

Commit 226691d

Browse files
committed
Make header size configurable
1 parent 3984fa6 commit 226691d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,13 @@ type HttpServerOptionsConfig struct {
534534
// See more information about setting request size limits here:
535535
// https://tyk.io/docs/api-management/traffic-transformation/#request-size-limits
536536
MaxRequestBodySize int64 `json:"max_request_body_size"`
537+
538+
// MaxHeaderBytes configures a maximum size limit for request header size (in bytes) for all APIs on the Gateway.
539+
//
540+
// Tyk Gateway will evaluate all API requests against this size limit and will respond with HTTP 431 status code if the header of the request is larger.
541+
//
542+
// Unset value, or a value of zero (default), means will use the Golang HTTP default value of 1 MB.
543+
MaxHeaderBytes int `json:"max_header_bytes"`
537544
}
538545

539546
type AuthOverrideConf struct {

gateway/proxy_muxer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ func (m *proxyMux) serve(gw *Gateway) {
465465
ReadTimeout: readTimeout,
466466
WriteTimeout: writeTimeout,
467467
Handler: handler,
468+
MaxHeaderBytes: conf.HttpServerOptions.MaxHeaderBytes,
468469
}
469470
if gw.ConnectionWatcher != nil {
470471
p.httpServer.ConnState = gw.ConnectionWatcher.OnStateChange

gateway/reverse_proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (gw *Gateway) TykNewSingleHostReverseProxy(target *url.URL, spec *APISpec,
220220
Handler: http.HandlerFunc(handler),
221221
ReadTimeout: 1 * time.Second,
222222
WriteTimeout: 1 * time.Second,
223-
MaxHeaderBytes: 1 << 20,
223+
MaxHeaderBytes: spec.GlobalConfig.HttpServerOptions.MaxHeaderBytes,
224224
}
225225
allHostsDownURL = "http://" + listener.Addr().String()
226226
go func() {

0 commit comments

Comments
 (0)