Class RateLimitInterceptor
- All Implemented Interfaces:
Interceptor
- See Also:
- Description
The rateLimiter plugin limits the number of requests of a client in a period of time. As a default the client requests are grouped by client-Ip address and then counted. There are lots of possibilities to group the requests using the keyExpression. The requests can even be counted from different clients together.
When the gateway is located behind a loadbalancer then the client-Ip address is not the one from the client but the address from the balancer. To get the real Ip-address loadbalancers, Web Application Firewalls and reverse proxies set the ip from the original client into the X-Forwarded-For HTTP header field. The limiter plugin can take the Ip-address from the header.
The X-Forwarded-For header can only be trusted when a trustworthy reverse proxy or load balancer is between the client and server. The gateway not should be reachable directly. Only activate this feature when you know what you are doing.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.predic8.membrane.core.interceptor.Interceptor
Interceptor.Flow -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe names are chosen based on - RateLimit Header Fields for HTTP, still a draftstatic final Stringstatic final StringNumber of seconds until the quota resets.Fields inherited from class com.predic8.membrane.core.interceptor.AbstractInterceptor
name, router -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringgetClientIp(Exchange exc) protected static StringgetOneBeforeTrustworthyProxy(List<String> l, int count) intinthandleRequest(Exchange exc) voidinit()Called after parsing is complete and this has been added to the object tree (whose root is Router).booleanvoidsetKeyExpression(String expression) voidsetRequestLimit(int limit) voidsetRequestLimitDuration(String duration) voidsetRequestLimitDuration(Duration duration) voidsetTrustedProxyCount(int trustedProxyCount) voidsetTrustedProxyList(String trustedProxyList) voidsetTrustForwardedFor(boolean trustForwardedFor) Methods inherited from class com.predic8.membrane.core.interceptor.AbstractInterceptor
getDisplayName, getFlow, getHelpId, getLongDescription, getMessage, getRouter, getRule, handleAbort, handleResponse, init, setDisplayName, setFlow
-
Field Details
-
X_RATELIMIT_DURATION
The names are chosen based on - RateLimit Header Fields for HTTP, still a draft- See Also:
-
X_RATELIMIT_LIMIT
- See Also:
-
X_RATELIMIT_RESET
Number of seconds until the quota resets.- See Also:
-
-
Constructor Details
-
RateLimitInterceptor
public RateLimitInterceptor() -
RateLimitInterceptor
-
-
Method Details
-
handleRequest
- Specified by:
handleRequestin interfaceInterceptor- Overrides:
handleRequestin classAbstractInterceptor- Throws:
Exception
-
init
Description copied from class:AbstractInterceptorCalled after parsing is complete and this has been added to the object tree (whose root is Router).- Overrides:
initin classAbstractInterceptor- Throws:
Exception
-
getClientIp
-
getOneBeforeTrustworthyProxy
-
getRequestLimit
public int getRequestLimit() -
setRequestLimit
public void setRequestLimit(int limit) - Default
- 1000
- Description
- Number of requests within the period of measurement.
-
getRequestLimitDuration
-
setRequestLimitDuration
- See Also:
- Default
- PT3600S
- Description
- Duration after the limit is reset in the ISO 8600 Duration format, e.g. PT10S for 10 seconds, PT5M for 5 minutes or PT8H for eight hours.
-
setRequestLimitDuration
-
setKeyExpression
- Default
- ip-address
- Description
- The expression the ratelimiter should use to group the requests before counting. The Spring Expression Language (SpEL) is used as language. In the expression the build-in variables request, header, properties can be used.
-
getKeyExpression
-
getTrustedProxyList
-
setTrustedProxyList
- Default
- empty String
- Description
- Comma separated list of trusted proxy servers and loadbalancers. Used to evaluate the X-Forwarded-For header.
If both trustedProxyList and trustedProxyCount is specified, the trustedProxyList is used to
determine the client ip address. To make this configuration active set
isTrustForwardedFor
to true.
-
getTrustedProxyCount
public int getTrustedProxyCount() -
setTrustedProxyCount
public void setTrustedProxyCount(int trustedProxyCount) - Default
- 0
- Description
- Number of trusted proxy servers and loadbalancers. Used to evaluate the X-Forwarded-For header.
If both
trustedProxyList
andtrustedProxyCount
is specified, the trustedProxyList is used to determine the client ip address. To make this configuration active setisTrustForwardedFor
to true.
-
isTrustForwardedFor
public boolean isTrustForwardedFor() -
setTrustForwardedFor
public void setTrustForwardedFor(boolean trustForwardedFor) - Default
- false
- Description
- Set this only to true if you know that are you doing. The function of the ratelimter relys on corrent X-ForwaredFor header values.
-
getShortDescription
- Specified by:
getShortDescriptionin interfaceInterceptor- Overrides:
getShortDescriptionin classAbstractInterceptor
-