我很好奇isWeb类中两个几乎完全相同的方法isHttporg.apache.shiro.web.utils.WebUtils之间的概念区别是什么,它们的行为有何不同?

public static boolean isWeb(Object requestPairSource) {
    return requestPairSource instanceof RequestPairSource
            && isWeb((RequestPairSource) requestPairSource);
}

public static boolean isHttp(Object requestPairSource) {
    return requestPairSource instanceof RequestPairSource
            && isHttp((RequestPairSource) requestPairSource);
}

private static boolean isWeb(RequestPairSource source) {
    ServletRequest request = source.getServletRequest();
    ServletResponse response = source.getServletResponse();
    return request != null && response != null;
}

private static boolean isHttp(RequestPairSource source) {
    ServletRequest request = source.getServletRequest();
    ServletResponse response = source.getServletResponse();
    return request instanceof HttpServletRequest
            && response instanceof HttpServletResponse;
}


附言这是Shiro和Java相关的问题,因为我都是新手。

最佳答案

区别在于isHttp检查HttpServletRequest和HttpServletResponse的请求和响应实例,而不仅仅是ServletRequest或ServletResponse,并且请求/响应可以为您提供HTTP信息(例如标头,方法等)。两者都是接口,填充取决于供应商容器/应用服务器

07-26 03:19