@@ -170,6 +170,7 @@ public HttpServer(HttpServerInfo httpServerInfo,
170170 "http-server-timeout" ,
171171 config .getTimeoutConcurrency (),
172172 config .getTimeoutThreads ());
173+
173174 // set up HTTP connector
174175 ServerConnector httpConnector ;
175176 if (config .isHttpEnabled ()) {
@@ -216,77 +217,20 @@ public HttpServer(HttpServerInfo httpServerInfo,
216217 server .addConnector (httpConnector );
217218 }
218219
219- List <String > includedCipherSuites = config .getHttpsIncludedCipherSuites ();
220- List <String > excludedCipherSuites = config .getHttpsExcludedCipherSuites ();
221-
222- // set up NIO-based HTTPS connector
223- ServerConnector httpsConnector ;
220+ // Set up NIO-based HTTPS connector.
224221 if (config .isHttpsEnabled ()) {
225- HttpConfiguration httpsConfiguration = new HttpConfiguration (baseHttpConfiguration );
226- httpsConfiguration .addCustomizer (new SecureRequestCustomizer ());
227-
228- SslContextFactory sslContextFactory = new SslContextFactory ();
229- Optional <KeyStore > pemKeyStore = tryLoadPemKeyStore (config );
230- if (pemKeyStore .isPresent ()) {
231- sslContextFactory .setKeyStore (pemKeyStore .get ());
232- sslContextFactory .setKeyStorePassword ("" );
233- }
234- else {
235- sslContextFactory .setKeyStorePath (config .getKeystorePath ());
236- sslContextFactory .setKeyStorePassword (config .getKeystorePassword ());
237- if (config .getKeyManagerPassword () != null ) {
238- sslContextFactory .setKeyManagerPassword (config .getKeyManagerPassword ());
239- }
240- }
241- if (config .getTrustStorePath () != null ) {
242- Optional <KeyStore > pemTrustStore = tryLoadPemTrustStore (config );
243- if (pemTrustStore .isPresent ()) {
244- sslContextFactory .setTrustStore (pemTrustStore .get ());
245- sslContextFactory .setTrustStorePassword ("" );
246- }
247- else {
248- sslContextFactory .setTrustStorePath (config .getTrustStorePath ());
249- sslContextFactory .setTrustStorePassword (config .getTrustStorePassword ());
250- }
251- }
252-
253- sslContextFactory .setIncludeCipherSuites (includedCipherSuites .toArray (new String [0 ]));
254- sslContextFactory .setExcludeCipherSuites (excludedCipherSuites .toArray (new String [0 ]));
255- sslContextFactory .setSecureRandomAlgorithm (config .getSecureRandomAlgorithm ());
256- sslContextFactory .setWantClientAuth (true );
257- sslContextFactory .setSslSessionTimeout ((int ) config .getSslSessionTimeout ().getValue (SECONDS ));
258- sslContextFactory .setSslSessionCacheSize (config .getSslSessionCacheSize ());
259- SslConnectionFactory sslConnectionFactory = new SslConnectionFactory (sslContextFactory , "http/1.1" );
260-
261- Integer acceptors = config .getHttpsAcceptorThreads ();
262- Integer selectors = config .getHttpsSelectorThreads ();
263- httpsConnector = createServerConnector (
264- httpServerInfo .getHttpsChannel (),
265- server ,
266- null ,
267- concurrentScheduler ,
268- firstNonNull (acceptors , -1 ),
269- firstNonNull (selectors , -1 ),
270- sslConnectionFactory ,
271- new HttpConnectionFactory (httpsConfiguration ));
272- httpsConnector .setName ("https" );
273- httpsConnector .setPort (httpServerInfo .getHttpsUri ().getPort ());
274- httpsConnector .setIdleTimeout (config .getNetworkMaxIdleTime ().toMillis ());
275- httpsConnector .setHost (nodeInfo .getBindIp ().getHostAddress ());
276- httpsConnector .setAcceptQueueSize (config .getHttpAcceptQueueSize ());
277-
278- // track connection statistics
279- ConnectionStatistics connectionStats = new ConnectionStatistics ();
280- httpsConnector .addBean (connectionStats );
281- this .httpsConnectionStats = new ConnectionStats (connectionStats );
282-
283- if (channelListener != null ) {
284- httpsConnector .addBean (channelListener );
285- }
286-
222+ ServerConnector httpsConnector = createHttpsConnector (config , nodeInfo , baseHttpConfiguration , concurrentScheduler ,
223+ channelListener , "https" , httpServerInfo .getHttpsUri ().getPort (), httpServerInfo .getHttpsChannel ());
287224 server .addConnector (httpsConnector );
288225 }
289226
227+ // Set up NIO-based alternative HTTPS connector.
228+ if (config .isHttpsEnabled () && config .isAlternativeHttpsEnabled ()) {
229+ ServerConnector alternativeHttpsConnector = createHttpsConnector (config , nodeInfo , baseHttpConfiguration , concurrentScheduler ,
230+ channelListener , "alternative-https" , httpServerInfo .getAlternativeHttpsUri ().getPort (), httpServerInfo .getAlternativeHttpsChannel ());
231+ server .addConnector (alternativeHttpsConnector );
232+ }
233+
290234 // set up NIO-based Admin connector
291235 ServerConnector adminConnector ;
292236 if (theAdminServlet != null && config .isAdminEnabled ()) {
@@ -308,8 +252,8 @@ public HttpServer(HttpServerInfo httpServerInfo,
308252 }
309253 sslContextFactory .setSecureRandomAlgorithm (config .getSecureRandomAlgorithm ());
310254 sslContextFactory .setWantClientAuth (true );
311- sslContextFactory .setIncludeCipherSuites (includedCipherSuites .toArray (new String [0 ]));
312- sslContextFactory .setExcludeCipherSuites (excludedCipherSuites .toArray (new String [0 ]));
255+ sslContextFactory .setIncludeCipherSuites (config . getHttpsIncludedCipherSuites () .toArray (new String [0 ]));
256+ sslContextFactory .setExcludeCipherSuites (config . getHttpsExcludedCipherSuites () .toArray (new String [0 ]));
313257 SslConnectionFactory sslConnectionFactory = new SslConnectionFactory (sslContextFactory , "http/1.1" );
314258 adminConnector = createServerConnector (
315259 httpServerInfo .getAdminChannel (),
@@ -370,7 +314,7 @@ public HttpServer(HttpServerInfo httpServerInfo,
370314 handlers .addHandler (gzipHandler );
371315 }
372316
373- handlers .addHandler (createServletContext (config , defaultServlet , servlets , parameters , filters , tokenManager , loginService , authorizer , "http" , "https" ));
317+ handlers .addHandler (createServletContext (config , defaultServlet , servlets , parameters , filters , tokenManager , loginService , authorizer , "http" , "https" , "alternative-https" ));
374318
375319 if (config .isRequestStatsEnabled ()) {
376320 RequestLogHandler statsRecorder = new RequestLogHandler ();
@@ -649,4 +593,84 @@ private static ServerConnector createServerConnector(
649593 connector .open (channel );
650594 return connector ;
651595 }
596+
597+ private ServerConnector createHttpsConnector (
598+ HttpServerConfig config ,
599+ NodeInfo nodeInfo ,
600+ HttpConfiguration baseHttpConfiguration ,
601+ ConcurrentScheduler concurrentScheduler ,
602+ HttpServerChannelListener channelListener ,
603+ String httpsName ,
604+ int httpsPort ,
605+ ServerSocketChannel socketChannel )
606+ throws IOException
607+ {
608+ ServerConnector httpsConnector ;
609+ List <String > includedCipherSuites = config .getHttpsIncludedCipherSuites ();
610+ List <String > excludedCipherSuites = config .getHttpsExcludedCipherSuites ();
611+
612+ HttpConfiguration httpsConfiguration = new HttpConfiguration (baseHttpConfiguration );
613+ httpsConfiguration .addCustomizer (new SecureRequestCustomizer ());
614+
615+ SslContextFactory sslContextFactory = new SslContextFactory ();
616+ Optional <KeyStore > pemKeyStore = tryLoadPemKeyStore (config );
617+ if (pemKeyStore .isPresent ()) {
618+ sslContextFactory .setKeyStore (pemKeyStore .get ());
619+ sslContextFactory .setKeyStorePassword ("" );
620+ }
621+ else {
622+ sslContextFactory .setKeyStorePath (config .getKeystorePath ());
623+ sslContextFactory .setKeyStorePassword (config .getKeystorePassword ());
624+ if (config .getKeyManagerPassword () != null ) {
625+ sslContextFactory .setKeyManagerPassword (config .getKeyManagerPassword ());
626+ }
627+ }
628+ if (config .getTrustStorePath () != null ) {
629+ Optional <KeyStore > pemTrustStore = tryLoadPemTrustStore (config );
630+ if (pemTrustStore .isPresent ()) {
631+ sslContextFactory .setTrustStore (pemTrustStore .get ());
632+ sslContextFactory .setTrustStorePassword ("" );
633+ }
634+ else {
635+ sslContextFactory .setTrustStorePath (config .getTrustStorePath ());
636+ sslContextFactory .setTrustStorePassword (config .getTrustStorePassword ());
637+ }
638+ }
639+
640+ sslContextFactory .setIncludeCipherSuites (includedCipherSuites .toArray (new String [0 ]));
641+ sslContextFactory .setExcludeCipherSuites (excludedCipherSuites .toArray (new String [0 ]));
642+ sslContextFactory .setSecureRandomAlgorithm (config .getSecureRandomAlgorithm ());
643+ sslContextFactory .setWantClientAuth (true );
644+ sslContextFactory .setSslSessionTimeout ((int ) config .getSslSessionTimeout ().getValue (SECONDS ));
645+ sslContextFactory .setSslSessionCacheSize (config .getSslSessionCacheSize ());
646+ SslConnectionFactory sslConnectionFactory = new SslConnectionFactory (sslContextFactory , "http/1.1" );
647+
648+ Integer acceptors = config .getHttpsAcceptorThreads ();
649+ Integer selectors = config .getHttpsSelectorThreads ();
650+ httpsConnector = createServerConnector (
651+ socketChannel ,
652+ server ,
653+ null ,
654+ concurrentScheduler ,
655+ firstNonNull (acceptors , -1 ),
656+ firstNonNull (selectors , -1 ),
657+ sslConnectionFactory ,
658+ new HttpConnectionFactory (httpsConfiguration ));
659+ httpsConnector .setName (httpsName );
660+ httpsConnector .setPort (httpsPort );
661+ httpsConnector .setIdleTimeout (config .getNetworkMaxIdleTime ().toMillis ());
662+ httpsConnector .setHost (nodeInfo .getBindIp ().getHostAddress ());
663+ httpsConnector .setAcceptQueueSize (config .getHttpAcceptQueueSize ());
664+
665+ // track connection statistics
666+ ConnectionStatistics connectionStats = new ConnectionStatistics ();
667+ httpsConnector .addBean (connectionStats );
668+ this .httpsConnectionStats = new ConnectionStats (connectionStats );
669+
670+ if (channelListener != null ) {
671+ httpsConnector .addBean (channelListener );
672+ }
673+
674+ return httpsConnector ;
675+ }
652676}
0 commit comments