-
Notifications
You must be signed in to change notification settings - Fork 471
Added support for http/2 to the Monitor web server #4982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,12 @@ | |
|
|
||
| import org.apache.accumulo.core.conf.AccumuloConfiguration; | ||
| import org.apache.accumulo.core.conf.Property; | ||
| import org.eclipse.jetty.server.AbstractConnectionFactory; | ||
| import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory; | ||
| import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; | ||
| import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory; | ||
| import org.eclipse.jetty.server.HttpConfiguration; | ||
| import org.eclipse.jetty.server.HttpConnectionFactory; | ||
| import org.eclipse.jetty.server.SecureRequestCustomizer; | ||
| import org.eclipse.jetty.server.Server; | ||
| import org.eclipse.jetty.server.ServerConnector; | ||
| import org.eclipse.jetty.server.SslConnectionFactory; | ||
|
|
@@ -41,30 +45,35 @@ public class EmbeddedWebServer { | |
| Property.MONITOR_SSL_TRUSTSTORE, Property.MONITOR_SSL_TRUSTSTOREPASS); | ||
|
|
||
| private final Server server; | ||
| private final ServerConnector connector; | ||
| private final ServletContextHandler handler; | ||
| private final boolean secure; | ||
|
|
||
| public EmbeddedWebServer(Monitor monitor, int port) { | ||
| private int actualHttpPort; | ||
| private ServerConnector connector; | ||
|
|
||
| public EmbeddedWebServer(final Monitor monitor, int httpPort) { | ||
| server = new Server(); | ||
| final AccumuloConfiguration conf = monitor.getContext().getConfiguration(); | ||
| secure = requireForSecure.stream().map(conf::get).allMatch(s -> s != null && !s.isEmpty()); | ||
|
|
||
| connector = new ServerConnector(server, getConnectionFactories(conf, secure)); | ||
| connector.setHost(monitor.getHostname()); | ||
| connector.setPort(port); | ||
| addConnectors(monitor, conf, httpPort, secure); | ||
|
|
||
| handler = | ||
| new ServletContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY); | ||
| handler.getSessionHandler().getSessionCookieConfig().setHttpOnly(true); | ||
| handler.setContextPath("/"); | ||
| } | ||
|
|
||
| private static AbstractConnectionFactory[] getConnectionFactories(AccumuloConfiguration conf, | ||
| private void addConnectors(Monitor monitor, AccumuloConfiguration conf, int httpPort, | ||
| boolean secure) { | ||
| HttpConnectionFactory httpFactory = new HttpConnectionFactory(); | ||
|
|
||
| boolean configureHttp2 = conf.getBoolean(Property.MONITOR_SUPPORT_HTTP2); | ||
|
|
||
| final HttpConfiguration httpConfig = new HttpConfiguration(); | ||
| httpConfig.setSendServerVersion(false); | ||
|
Comment on lines
+72
to
+73
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unrelated, and only hides the Jetty version. Is that something we want to keep independently of this PR? What's the intention here? |
||
|
|
||
| if (secure) { | ||
| LOG.debug("Configuring Jetty to use TLS"); | ||
| LOG.debug("Configuring Jetty with TLS"); | ||
| final SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); | ||
| // If the key password is the same as the keystore password, we don't | ||
| // have to explicitly set it. Thus, if the user doesn't provide a key | ||
|
|
@@ -95,21 +104,47 @@ private static AbstractConnectionFactory[] getConnectionFactories(AccumuloConfig | |
| sslContextFactory.setIncludeProtocols(includeProtocols.split(",")); | ||
| } | ||
|
|
||
| SslConnectionFactory sslFactory = | ||
| new SslConnectionFactory(sslContextFactory, httpFactory.getProtocol()); | ||
| return new AbstractConnectionFactory[] {sslFactory, httpFactory}; | ||
| if (!configureHttp2) { | ||
| HttpConnectionFactory http11 = new HttpConnectionFactory(httpConfig); | ||
| SslConnectionFactory tls = | ||
| new SslConnectionFactory(sslContextFactory, http11.getProtocol()); | ||
| connector = new ServerConnector(server, tls, http11); | ||
| } else { | ||
| LOG.debug("Enabling http2 support"); | ||
| httpConfig.addCustomizer(new SecureRequestCustomizer()); | ||
| HttpConnectionFactory http11 = new HttpConnectionFactory(httpConfig); | ||
| ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory(); | ||
| alpn.setDefaultProtocol(http11.getProtocol()); | ||
| HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(httpConfig); | ||
| SslConnectionFactory tls = new SslConnectionFactory(sslContextFactory, alpn.getProtocol()); | ||
| connector = new ServerConnector(server, tls, alpn, http2, http11); | ||
| } | ||
| connector.setHost(monitor.getHostname()); | ||
| connector.setPort(httpPort); | ||
| server.addConnector(connector); | ||
| } else { | ||
| LOG.debug("Not configuring Jetty to use TLS"); | ||
| return new AbstractConnectionFactory[] {httpFactory}; | ||
| LOG.debug("Configuring Jetty without TLS"); | ||
| if (!configureHttp2) { | ||
| HttpConnectionFactory http11 = new HttpConnectionFactory(httpConfig); | ||
| connector = new ServerConnector(server, http11); | ||
| } else { | ||
| LOG.debug("Enabling http2 support"); | ||
| HttpConnectionFactory http11 = new HttpConnectionFactory(httpConfig); | ||
| HTTP2CServerConnectionFactory http2 = new HTTP2CServerConnectionFactory(httpConfig); | ||
| connector = new ServerConnector(server, http11, http2); | ||
| } | ||
| connector.setHost(monitor.getHostname()); | ||
| connector.setPort(httpPort); | ||
| server.addConnector(connector); | ||
| } | ||
| } | ||
|
|
||
| public void addServlet(ServletHolder restServlet, String where) { | ||
| handler.addServlet(restServlet, where); | ||
| } | ||
|
|
||
| public int getPort() { | ||
| return connector.getLocalPort(); | ||
| public int getHttpPort() { | ||
| return this.actualHttpPort; | ||
| } | ||
|
|
||
| public boolean isSecure() { | ||
|
|
@@ -118,9 +153,9 @@ public boolean isSecure() { | |
|
|
||
| public void start() { | ||
| try { | ||
| server.addConnector(connector); | ||
| server.setHandler(handler); | ||
| server.start(); | ||
| this.actualHttpPort = connector.getLocalPort(); | ||
| } catch (Exception e) { | ||
| stop(); | ||
| throw new RuntimeException(e); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be configurable. All modern browsers support it. If it improves our monitor's performance in any way, it should just be used automatically when we use TLS.
For the technical reasons listed on https://stackoverflow.com/a/46789195/196405 , I suggest not bothering to support it when TLS is off.