Search in sources :

Example 11 with ForwardedRequestCustomizer

use of org.eclipse.jetty.server.ForwardedRequestCustomizer in project zeppelin by apache.

the class ZeppelinServer method initServerConnector.

private static void initServerConnector(Server server, int port, int sslPort) {
    ServerConnector connector;
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.addCustomizer(new ForwardedRequestCustomizer());
    httpConfig.setSendServerVersion(conf.sendJettyName());
    httpConfig.setRequestHeaderSize(conf.getJettyRequestHeaderSize());
    if (conf.useSsl()) {
        LOG.debug("Enabling SSL for Zeppelin Server on port {}", sslPort);
        httpConfig.setSecureScheme(HttpScheme.HTTPS.asString());
        httpConfig.setSecurePort(sslPort);
        HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
        httpsConfig.addCustomizer(new SecureRequestCustomizer());
        SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(getSslContextFactory(conf), HttpVersion.HTTP_1_1.asString());
        HttpConnectionFactory httpsConnectionFactory = new HttpConnectionFactory(httpsConfig);
        connector = new ServerConnector(server, sslConnectionFactory, httpsConnectionFactory);
        connector.setPort(sslPort);
        connector.addBean(new JettySslHandshakeMetrics(Metrics.globalRegistry, Tags.empty()));
    } else {
        HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpConfig);
        connector = new ServerConnector(server, httpConnectionFactory);
        connector.setPort(port);
    }
    // Set some timeout options to make debugging easier.
    int timeout = 1000 * 30;
    connector.setIdleTimeout(timeout);
    connector.setHost(conf.getServerAddress());
    connector.addBean(new JettyConnectionMetrics(Metrics.globalRegistry, Tags.empty()));
    server.addConnector(connector);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) JettySslHandshakeMetrics(io.micrometer.core.instrument.binder.jetty.JettySslHandshakeMetrics) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) JettyConnectionMetrics(io.micrometer.core.instrument.binder.jetty.JettyConnectionMetrics) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer)

Example 12 with ForwardedRequestCustomizer

use of org.eclipse.jetty.server.ForwardedRequestCustomizer in project Openfire by igniterealtime.

the class HttpBindManager method configureProxiedConnector.

private void configureProxiedConnector(HttpConfiguration httpConfig) {
    // Refer to http://eclipse.org/jetty/documentation/current/configuring-connectors.html
    if (isXFFEnabled()) {
        ForwardedRequestCustomizer customizer = new ForwardedRequestCustomizer();
        // default: "X-Forwarded-For"
        String forwardedForHeader = HTTP_BIND_FORWARDED_FOR.getValue();
        if (forwardedForHeader != null) {
            customizer.setForwardedForHeader(forwardedForHeader);
        }
        // default: "X-Forwarded-Server"
        String forwardedServerHeader = HTTP_BIND_FORWARDED_SERVER.getValue();
        if (forwardedServerHeader != null) {
            customizer.setForwardedServerHeader(forwardedServerHeader);
        }
        // default: "X-Forwarded-Host"
        String forwardedHostHeader = HTTP_BIND_FORWARDED_HOST.getValue();
        if (forwardedHostHeader != null) {
            customizer.setForwardedHostHeader(forwardedHostHeader);
        }
        // default: none
        String hostName = getXFFHostName();
        if (hostName != null) {
            customizer.setHostHeader(hostName);
        }
        httpConfig.addCustomizer(customizer);
    }
    httpConfig.setRequestHeaderSize(HTTP_BIND_REQUEST_HEADER_SIZE.getValue());
}
Also used : ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer)

Aggregations

ForwardedRequestCustomizer (org.eclipse.jetty.server.ForwardedRequestCustomizer)12 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)10 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)9 ServerConnector (org.eclipse.jetty.server.ServerConnector)8 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)5 Server (org.eclipse.jetty.server.Server)5 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)5 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)5 MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)4 ArrayList (java.util.ArrayList)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)2 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)2 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)2 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)2 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)2 StdErrLog (org.eclipse.jetty.util.log.StdErrLog)2 ScheduledExecutorScheduler (org.eclipse.jetty.util.thread.ScheduledExecutorScheduler)2