我只是建立一個小的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