我只是建立一个小的PoC,我使用带有http/2的Jetty 9.3.9.M1嵌入式服务器和PushBuilder API与Apache Wicket一起将资源推送到客户。Jetty响应状态200而不是304,而使用http2
我用下面的服务器设置:
Server server = new Server();
// HTTP Configuration
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecureScheme("https");
http_config.setSecurePort(8443);
http_config.setSendXPoweredBy(true);
http_config.setSendServerVersion(true);
// keytool -keystore keystore -alias jetty -genkey -keyalg RSA
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(new File(".","keystore").getCanonicalPath());
sslContextFactory.setKeyStorePassword("123456789");
sslContextFactory.setKeyManagerPassword("123456789");
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
sslContextFactory.setUseCipherSuitesOrder(true);
// HTTPS Configuration
HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
// HTTP Connector
ServerConnector http1 = new ServerConnector(server, new HttpConnectionFactory(http_config),
new HTTP2CServerConnectionFactory(http_config));
http1.setPort(8080);
server.addConnector(http1);
// HTTP/2 Connection Factory
HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(https_config);
NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(http1.getDefaultProtocol());
// SSL Connection Factory
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
// HTTP/2 Connector
ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, http2,
new HttpConnectionFactory(https_config));
http2Connector.setPort(8443);
server.addConnector(http2Connector);
WebAppContext webAppContext = new WebAppContext();
webAppContext.setServer(server);
webAppContext.setContextPath("/");
webAppContext.setWar("src/main/webapp");
server.setHandler(webAppContext);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.addHandler(webAppContext);
server.setHandler(contexts);
ALPN.debug = false;
server.start();
server.join();
现在我面临的问题是,当我做了HTTP/1.1请求的资源是这样的:
状态代码304在第二个请求后显示在chrome调试器中
如果我对同一个资源执行http/2.0请求:
状态码200显示在每个请求 - 这似乎是客户端不缓存它。
这里是链接到Git项目:提前https://github.com/klopfdreh/jetty-http2-example
亲切的问候和感谢。
试用HTTPS和1.1。 –
当我用http/1.1使用HTTPS时,它也像预期的那样工作。在第二次请求之后,资源被缓存,并且304被打印为状态码。我只改变了SslConnectionFactory的构造函数,并在http1.getDefaultProtocol中作为第二个参数。 – klopfdreh
你是在推'css'还是直接使用浏览器请求它? – sbordet