ProxyFilter.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:lemon 作者:
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    if (enable) {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;
        String contextPath = req.getContextPath();
        String requestUri = req.getRequestURI();
        String path = requestUri.substring(contextPath.length());

        // 如果在黑名单中,直接略过
        if (isExcluded(path)) {
            chain.doFilter(request, response);

            return;
        }

        // 如果符合redirect规则,进行跳转
        if (urlPatternMatcher.shouldRedirect(path)) {
            res.sendRedirect(contextPath + path + "/");

            return;
        }

        // 如果都没问题,才会继续进行判断
        if (urlPatternMatcher.matches(path)) {
            filter.doFilter(request, response, chain);
        } else {
            chain.doFilter(request, response);
        }
    } else {
        chain.doFilter(request, response);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号