使用HTTP / 2 PUSH时的CloseNowException

时间:2019-07-16 18:11:03

标签: java spring spring-boot push http2

我正在尝试实现一种在Spring Boot 2中使用HTTP / 2 PUSH推送公共静态资源的机制。

基本上,有多个视图共享同一个图标图标图像以及一些JS和CSS库。

到目前为止,我已经创建了一个拦截器来进行推送:

@Component
public class GlobalResourcePushInterceptor implements HandlerInterceptor {

    @Override
    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) {
        if (modelAndView != null) {
            val pushBuilder = request.newPushBuilder();
            if (null != pushBuilder) {
                // Images
                pushBuilder.path("images/favicon-192x192.png").push();

                // CSS
                pushBuilder.path("css/base.css").push();
                pushBuilder.path("webjars/Semantic-UI/2.4.1/semantic.css").push();

                // JS
                pushBuilder.path("webjars/jquery/3.4.1/jquery.min.js").push();
                pushBuilder.path("webjars/Semantic-UI/2.4.1/semantic.js").push();
                pushBuilder.path("js/generic.js").push();
            }
        }
    }
}

但是此结果非常不一致。有时页面加载成功,但是经常出现以下错误:

2019-07-16 18:56:29.757 ERROR 6945 --- [nio-3333-exec-9] s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request [/webjars/jquery/3.4.1/jquery.min.js] and exception [newPosition < 0: (16921 < 0)] as the response has already been committed. As a result, the response may have the wrong status code.
2019-07-16 18:56:29.758  WARN 6945 --- [nio-3333-exec-9] o.a.c.c.C.[Tomcat].[localhost]           : Exception Processing ErrorPage[errorCode=0, location=/error]

org.apache.coyote.CloseNowException: Connection [21], Stream [44], This stream is not writable
    at org.apache.coyote.http2.Http2UpgradeHandler.reserveWindowSize(Http2UpgradeHandler.java:756) ~[tomcat-embed-core-9.0.19.jar:9.0.19]
    at org.apache.coyote.http2.Stream$StreamOutputBuffer.flush(Stream.java:922) ~[tomcat-embed-core-9.0.19.jar:9.0.19]
    at org.apache.coyote.http2.Stream$StreamOutputBuffer.doWrite(Stream.java:843) ~[tomcat-embed-core-9.0.19.jar:9.0.19]
    at org.apache.coyote.http2.Http2OutputBuffer.doWrite(Http2OutputBuffer.java:59) ~[tomcat-embed-core-9.0.19.jar:9.0.19]
    at org.apache.coyote.Response.doWrite(Response.java:599) ~[tomcat-embed-core-9.0.19.jar:9.0.19]

使用HTTP / 2推送和Spring Boot 2推送共享静态资源的最佳方法是什么?

0 个答案:

没有答案