Last active
May 2, 2022 10:07
-
-
Save reevik/1a8345e08a7c1d83a3cc428cecfe31fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean preHandle( | |
HttpServletRequest request, | |
HttpServletResponse response, | |
Object handler) { | |
Map<String, String> pathVars = (Map<String, String>) | |
request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); | |
if (!rateLimiter.tryAccess(pathVars.get(USER_ID))) { | |
response.setStatus(TOO_MANY_REQUEST); | |
response.setHeader(RETRY_AFTER, IN_300_SECS); | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment