Merge pull request #10378 from tapankavasthi/master
Use shouldNotFilter to exclude URLs for a Filter
This commit is contained in:
commit
28436e3bc1
|
@ -12,19 +12,22 @@ import java.io.IOException;
|
|||
@Order(1)
|
||||
public class HeaderValidatorFilter extends OncePerRequestFilter {
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
String path = request.getRequestURI();
|
||||
if ("/health".equals(path)) {
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
protected void doFilterInternal(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
FilterChain filterChain)
|
||||
throws ServletException,
|
||||
IOException {
|
||||
String countryCode = request.getHeader("X-Country-Code");
|
||||
if (!"US".equals(countryCode)) {
|
||||
response.sendError(HttpStatus.BAD_REQUEST.value(), "Invalid Locale");
|
||||
return;
|
||||
}
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
|
||||
String path = request.getRequestURI();
|
||||
return "/health".equals(path);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue