4

最近我们在servlet 3.0和spring 3.2中使用了异步特性,但是我们的ShallowEtagHeaderFilter根本没有效果,我认为它必须是框架在我的内容被处理之前刷新响应......如何解决它?有人有经验吗?

4

1 回答 1

0

参考 Spring 4.3.5 中 ShallowEtagFilter 的代码片段,

protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {

    HttpServletResponse responseToUse = response;
    if (!isAsyncDispatch(request) && !(response instanceof ContentCachingResponseWrapper)) {
        responseToUse = new HttpStreamingAwareContentCachingResponseWrapper(response, request);
    }

    filterChain.doFilter(request, responseToUse);

    if (!isAsyncStarted(request) && !isContentCachingDisabled(request)) {
        updateResponse(request, responseToUse);
    }
}

/**
     * Whether request processing is in asynchronous mode meaning that the
     * response will not be committed after the current thread is exited.
     * @param request the current request
     * @since 3.2
     * @see WebAsyncManager#isConcurrentHandlingStarted()
     */
    protected boolean isAsyncStarted(HttpServletRequest request) {
        return WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted();
    }

使用 async servlet 时,条件不成立,即不会调用生成 etag 的业务逻辑。

于 2017-09-04T07:19:19.630 回答