[英]How to enable http/2 on an embedded Jetty 10?
我嘗試在我的 Jetty 10.0.11 上啟用 http/2,但沒有運氣。 我使用以下代碼創建 ServerConnector:
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSendServerVersion( false );
httpConfig.setSendXPoweredBy( false );
HttpConnectionFactory http1 = new HttpConnectionFactory( httpConfig );
httpConfig.addCustomizer( new SecureRequestCustomizer( false ) ); // for https://localhost
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
// ... load the certificate
sslContextFactory.setCipherComparator( HTTP2Cipher.COMPARATOR );
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() ); // for service worker
//HTTP2CServerConnectionFactory http2 = new HTTP2CServerConnectionFactory( httpConfig );
HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory( httpConfig );
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol( http1.getProtocol() );
SslConnectionFactory ssl = new SslConnectionFactory( sslContextFactory, alpn.getProtocol() );
ServerConnector connector = new ServerConnector( this, acceptors, selectors, ssl, alpn, http2, http1 );
connector.setReuseAddress( false );
connector.setPort( port );
connector.setAcceptQueueSize( MAX_CONCURRENT_REQUESTS.get().intValue() );
我為 http/2 添加了以下附加庫:
如果我使用https://localhost
進行嘗試,則瀏覽器(Chrome)正在使用 http/1.1。
問題的原因是:
錯誤的:
HTTP2CServerConnectionFactory http2 = new HTTP2CServerConnectionFactory( httpConfig );
正確的:
HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory( httpConfig );
為什么要創建具有如此相似類名的類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.