marcosbarbero / spring-cloud-zuul-ratelimit

Rate limit auto-configure for Spring Cloud Netflix Zuul

Home Page:https://blog.marcosbarbero.com/spring-cloud-netflix-zuul-rate-limit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to use custom header for ratelimitting.

harshitgoel96 opened this issue · comments

We have a custom api implementation where the authentication credentials are passed in a custom header. we want to have rate limiting based on the user/token passed in custom header. but the application is failing to start.

configuration

ratelimit:
enabled: true
repository: JPA
policy-list:
stock:
- limit: 5
refresh-interval: 60
type:
- user
- type:
- http_header=x-access-token

Error while startup.

Failed to bind properties under 'zuul.ratelimit.policy-list.stock[1].type[0]' to com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.properties.RateLimitProperties$Policy$MatchType:

Property: zuul.ratelimit.policy-list.stock[1].type[0]
Value: http_header=x-access-token
Origin: class path resource [application.yml]:114:15
Reason: failed to convert java.lang.String to com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.properties.RateLimitProperties$Policy$MatchType

even keeping just http_header fails with same error , sample below.

stock:
- limit: 5
refresh-interval: 60
type:
- http_header=x-access-token

spring-cloud-starter-netflix-zuul version : 2.0.1.Release
spring-cloud-zuul-ratelimit version: 2.2.0

Hello @harshitgoel96, thanks for getting in touch, we will get back to you asap! If you have issues in the 1.x.x.RELEASE line we recommend you to update to the latest version, unfortunately this line is not supported anymore.

Hi @harshitgoel96, it looks like your configuration is correct. Would it be possible for you to share a demo project reproducing the problem?

@marcosbarbero where you able to replicate the issue ?

Hi @harshitgoel96 apologies for the delay. I found the issue.

The version you're using doesn't support this feature. You can update to the latest version to get it working.

<dependency>
    <groupId>com.marcosbarbero.cloud</groupId>
    <artifactId>spring-cloud-zuul-ratelimit</artifactId>
    <version>2.4.2.RELEASE</version>
</dependency>

@marcosbarbero will check and update you shortly.

@marcosbarbero thanks for help mate. got it working by updating the version.