Skip to content

Instantly share code, notes, and snippets.

@reevik
Last active May 2, 2022 10:07
Show Gist options
  • Save reevik/1a8345e08a7c1d83a3cc428cecfe31fa to your computer and use it in GitHub Desktop.
Save reevik/1a8345e08a7c1d83a3cc428cecfe31fa to your computer and use it in GitHub Desktop.
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