diff --git a/plugins/plugins/limitcountredis/config_test.go b/plugins/plugins/limitcountredis/config_test.go index f01de771..6e40ad50 100644 --- a/plugins/plugins/limitcountredis/config_test.go +++ b/plugins/plugins/limitcountredis/config_test.go @@ -66,6 +66,10 @@ func TestConfig(t *testing.T) { name: "pass", input: `{"address":"127.0.0.1:6479", "rules":[{"count":1,"timeWindow":"1s"}], "prefix":"test"}`, }, + { + name: "disable x-envoy-ratelimited header", + input: `{"address":"127.0.0.1:6479", "rules":[{"count":1,"timeWindow":"1s"}], "prefix":"test", "disable_x_envoy_ratelimited_header": true}`, + }, } for _, tt := range tests { diff --git a/plugins/plugins/limitcountredis/filter.go b/plugins/plugins/limitcountredis/filter.go index 8a10b717..dd86d094 100644 --- a/plugins/plugins/limitcountredis/filter.go +++ b/plugins/plugins/limitcountredis/filter.go @@ -161,7 +161,7 @@ func (f *filter) DecodeHeaders(headers api.RequestHeaderMap, endStream bool) api remain := ress[2*i].(int64) if remain < 0 { hdr := http.Header{} - if config.EnableLimitQuotaHeaders { + if !config.DisableXEnvoyRatelimitedHeader { hdr.Set("x-envoy-ratelimited", "true") } status := 429 diff --git a/types/plugins/limitcountredis/config.pb.go b/types/plugins/limitcountredis/config.pb.go index 4dfb1d59..f36d228c 100644 --- a/types/plugins/limitcountredis/config.pb.go +++ b/types/plugins/limitcountredis/config.pb.go @@ -170,7 +170,8 @@ type Config struct { StatusOnError v1.StatusCode `protobuf:"varint,9,opt,name=status_on_error,json=statusOnError,proto3,enum=types.plugins.api.v1.StatusCode" json:"status_on_error,omitempty"` RateLimitedStatus v1.StatusCode `protobuf:"varint,10,opt,name=rate_limited_status,json=rateLimitedStatus,proto3,enum=types.plugins.api.v1.StatusCode" json:"rate_limited_status,omitempty"` // There is no special reason to limit the length <=128, just to avoid too long string - Prefix string `protobuf:"bytes,12,opt,name=prefix,proto3" json:"prefix,omitempty"` + Prefix string `protobuf:"bytes,12,opt,name=prefix,proto3" json:"prefix,omitempty"` + DisableXEnvoyRatelimitedHeader bool `protobuf:"varint,13,opt,name=disable_x_envoy_ratelimited_header,json=disableXEnvoyRatelimitedHeader,proto3" json:"disable_x_envoy_ratelimited_header,omitempty"` } func (x *Config) Reset() { @@ -296,6 +297,13 @@ func (x *Config) GetPrefix() string { return "" } +func (x *Config) GetDisableXEnvoyRatelimitedHeader() bool { + if x != nil { + return x.DisableXEnvoyRatelimitedHeader + } + return false +} + type isConfig_Source interface { isConfig_Source() } @@ -337,7 +345,7 @@ var file_types_plugins_limitcountredis_config_proto_rawDesc = []byte{ 0x22, 0x31, 0x0a, 0x07, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x12, 0x26, 0x0a, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x92, 0x01, 0x02, 0x08, 0x01, 0x52, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, - 0x73, 0x65, 0x73, 0x22, 0xd9, 0x04, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1a, + 0x73, 0x65, 0x73, 0x22, 0xa5, 0x05, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1a, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x42, 0x0a, 0x07, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x74, 0x79, @@ -374,11 +382,16 @@ var file_types_plugins_limitcountredis_config_proto_rawDesc = []byte{ 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x22, 0x0a, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xfa, 0x42, 0x07, 0x72, 0x05, 0x10, 0x01, 0x18, 0x80, 0x01, 0x52, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, - 0x42, 0x0d, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x03, 0xf8, 0x42, 0x01, 0x42, - 0x2c, 0x5a, 0x2a, 0x6d, 0x6f, 0x73, 0x6e, 0x2e, 0x69, 0x6f, 0x2f, 0x68, 0x74, 0x6e, 0x6e, 0x2f, - 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x2f, 0x6c, 0x69, - 0x6d, 0x69, 0x74, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x65, 0x64, 0x69, 0x73, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x4a, 0x0a, 0x22, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x78, 0x5f, 0x65, 0x6e, + 0x76, 0x6f, 0x79, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x5f, + 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1e, 0x64, 0x69, + 0x73, 0x61, 0x62, 0x6c, 0x65, 0x58, 0x45, 0x6e, 0x76, 0x6f, 0x79, 0x52, 0x61, 0x74, 0x65, 0x6c, + 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x42, 0x0d, 0x0a, 0x06, + 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x03, 0xf8, 0x42, 0x01, 0x42, 0x2c, 0x5a, 0x2a, 0x6d, + 0x6f, 0x73, 0x6e, 0x2e, 0x69, 0x6f, 0x2f, 0x68, 0x74, 0x6e, 0x6e, 0x2f, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x2f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x65, 0x64, 0x69, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( diff --git a/types/plugins/limitcountredis/config.pb.validate.go b/types/plugins/limitcountredis/config.pb.validate.go index 517437cc..85af4aca 100644 --- a/types/plugins/limitcountredis/config.pb.validate.go +++ b/types/plugins/limitcountredis/config.pb.validate.go @@ -393,6 +393,8 @@ func (m *Config) validate(all bool) error { errors = append(errors, err) } + // no validation rules for DisableXEnvoyRatelimitedHeader + oneofSourcePresent := false switch v := m.Source.(type) { case *Config_Address: diff --git a/types/plugins/limitcountredis/config.proto b/types/plugins/limitcountredis/config.proto index 8b8f9345..023cfc2f 100644 --- a/types/plugins/limitcountredis/config.proto +++ b/types/plugins/limitcountredis/config.proto @@ -58,4 +58,6 @@ message Config { // There is no special reason to limit the length <=128, just to avoid too long string string prefix = 12 [(validate.rules).string = {min_len: 1, max_len: 128}]; + + bool disable_x_envoy_ratelimited_header = 13; }