use of org.eclipse.jetty.server.ForwardedRequestCustomizer in project camel by apache.
the class JettyHttpComponent9 method createConnectorJettyInternal.
protected AbstractConnector createConnectorJettyInternal(Server server, JettyHttpEndpoint endpoint, SslContextFactory sslcf) {
try {
String host = endpoint.getHttpUri().getHost();
int porto = endpoint.getPort();
org.eclipse.jetty.server.HttpConfiguration httpConfig = new org.eclipse.jetty.server.HttpConfiguration();
httpConfig.setSendServerVersion(endpoint.isSendServerVersion());
httpConfig.setSendDateHeader(endpoint.isSendDateHeader());
httpConfig.setSendDateHeader(endpoint.isSendDateHeader());
if (requestBufferSize != null) {
// Does not work
//httpConfig.setRequestBufferSize(requestBufferSize);
}
if (requestHeaderSize != null) {
httpConfig.setRequestHeaderSize(requestHeaderSize);
}
if (responseBufferSize != null) {
httpConfig.setOutputBufferSize(responseBufferSize);
}
if (responseHeaderSize != null) {
httpConfig.setResponseHeaderSize(responseHeaderSize);
}
if (useXForwardedForHeader) {
httpConfig.addCustomizer(new ForwardedRequestCustomizer());
}
HttpConnectionFactory httpFactory = new org.eclipse.jetty.server.HttpConnectionFactory(httpConfig);
ArrayList<ConnectionFactory> connectionFactories = new ArrayList<ConnectionFactory>();
ServerConnector result = new org.eclipse.jetty.server.ServerConnector(server);
if (sslcf != null) {
httpConfig.addCustomizer(new org.eclipse.jetty.server.SecureRequestCustomizer());
SslConnectionFactory scf = new org.eclipse.jetty.server.SslConnectionFactory(sslcf, "HTTP/1.1");
connectionFactories.add(scf);
// The protocol name can be "SSL" or "SSL-HTTP/1.1" depending on the version of Jetty
result.setDefaultProtocol(scf.getProtocol());
}
connectionFactories.add(httpFactory);
result.setConnectionFactories(connectionFactories);
result.setPort(porto);
if (host != null) {
result.setHost(host);
}
if (getSslSocketConnectorProperties() != null && "https".equals(endpoint.getProtocol())) {
// must copy the map otherwise it will be deleted
Map<String, Object> properties = new HashMap<String, Object>(getSslSocketConnectorProperties());
IntrospectionSupport.setProperties(sslcf, properties);
if (properties.size() > 0) {
throw new IllegalArgumentException("There are " + properties.size() + " parameters that couldn't be set on the SocketConnector." + " Check the uri if the parameters are spelt correctly and that they are properties of the SelectChannelConnector." + " Unknown parameters=[" + properties + "]");
}
}
return result;
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
use of org.eclipse.jetty.server.ForwardedRequestCustomizer in project winstone by jenkinsci.
the class HttpConnectorFactory method start.
public boolean start(Map args, Server server) throws IOException {
// Load resources
int listenPort = Option.HTTP_PORT.get(args);
String listenAddress = Option.HTTP_LISTEN_ADDRESS.get(args);
int keepAliveTimeout = Option.HTTP_KEEP_ALIVE_TIMEOUT.get(args);
if (listenPort < 0) {
return false;
} else {
ServerConnector connector = createConnector(server);
connector.setPort(listenPort);
connector.setHost(listenAddress);
connector.setIdleTimeout(keepAliveTimeout);
HttpConfiguration config = connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
config.addCustomizer(new ForwardedRequestCustomizer());
config.setRequestHeaderSize(Option.REQUEST_HEADER_SIZE.get(args));
server.addConnector(connector);
return true;
}
}
use of org.eclipse.jetty.server.ForwardedRequestCustomizer in project winstone by jenkinsci.
the class HttpsConnectorFactory method start.
public boolean start(Map args, Server server) throws IOException {
int listenPort = Option.HTTPS_PORT.get(args);
String listenAddress = Option.HTTPS_LISTEN_ADDRESS.get(args);
int keepAliveTimeout = Option.HTTPS_KEEP_ALIVE_TIMEOUT.get(args);
if (listenPort < 0) {
// not running HTTPS listener
return false;
}
configureSsl(args, server);
ServerConnector connector = createConnector(server, args);
connector.setPort(listenPort);
connector.setHost(listenAddress);
connector.setIdleTimeout(keepAliveTimeout);
HttpConfiguration config = connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
config.addCustomizer(new ForwardedRequestCustomizer());
config.setRequestHeaderSize(Option.REQUEST_HEADER_SIZE.get(args));
server.addConnector(connector);
return true;
}
use of org.eclipse.jetty.server.ForwardedRequestCustomizer in project dropwizard by dropwizard.
the class HttpConnectorFactory method buildHttpConfiguration.
protected HttpConfiguration buildHttpConfiguration() {
final HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setHeaderCacheSize((int) headerCacheSize.toBytes());
httpConfig.setOutputBufferSize((int) outputBufferSize.toBytes());
httpConfig.setRequestHeaderSize((int) maxRequestHeaderSize.toBytes());
httpConfig.setResponseHeaderSize((int) maxResponseHeaderSize.toBytes());
httpConfig.setSendDateHeader(useDateHeader);
httpConfig.setSendServerVersion(useServerHeader);
httpConfig.setMinResponseDataRate(minResponseDataPerSecond.toBytes());
httpConfig.setMinRequestDataRate(minRequestDataPerSecond.toBytes());
httpConfig.setRequestCookieCompliance(requestCookieCompliance);
httpConfig.setResponseCookieCompliance(responseCookieCompliance);
if (useForwardedHeaders) {
httpConfig.addCustomizer(new ForwardedRequestCustomizer());
}
return httpConfig;
}
use of org.eclipse.jetty.server.ForwardedRequestCustomizer in project gerrit by GerritCodeReview.
the class JettyServer method listen.
private Connector[] listen(Server server, Config cfg) {
// OpenID and certain web-based single-sign-on products can cause
// some very long headers, especially in the Referer header. We
// need to use a larger default header size to ensure we have
// the space required.
//
final int requestHeaderSize = cfg.getInt("httpd", "requestheadersize", 16386);
final URI[] listenUrls = listenURLs(cfg);
final boolean reuseAddress = cfg.getBoolean("httpd", "reuseaddress", true);
final int acceptors = cfg.getInt("httpd", "acceptorThreads", 2);
final AuthType authType = cfg.getEnum("auth", null, "type", AuthType.OPENID);
reverseProxy = isReverseProxied(listenUrls);
final Connector[] connectors = new Connector[listenUrls.length];
for (int idx = 0; idx < listenUrls.length; idx++) {
final URI u = listenUrls[idx];
final int defaultPort;
final ServerConnector c;
HttpConfiguration config = defaultConfig(requestHeaderSize);
if (AuthType.CLIENT_SSL_CERT_LDAP.equals(authType) && !"https".equals(u.getScheme())) {
throw new IllegalArgumentException("Protocol '" + u.getScheme() + "' " + " not supported in httpd.listenurl '" + u + "' when auth.type = '" + AuthType.CLIENT_SSL_CERT_LDAP.name() + "'; only 'https' is supported");
}
if ("http".equals(u.getScheme())) {
defaultPort = 80;
c = newServerConnector(server, acceptors, config);
} else if ("https".equals(u.getScheme())) {
SslContextFactory.Server ssl = new SslContextFactory.Server();
final Path keystore = getFile(cfg, "sslkeystore", "etc/keystore");
String password = cfg.getString("httpd", null, "sslkeypassword");
if (password == null) {
password = "gerrit";
}
ssl.setKeyStorePath(keystore.toAbsolutePath().toString());
ssl.setTrustStorePath(keystore.toAbsolutePath().toString());
ssl.setKeyStorePassword(password);
ssl.setTrustStorePassword(password);
if (AuthType.CLIENT_SSL_CERT_LDAP.equals(authType)) {
ssl.setNeedClientAuth(true);
Path crl = getFile(cfg, "sslCrl", "etc/crl.pem");
if (Files.exists(crl)) {
ssl.setCrlPath(crl.toAbsolutePath().toString());
ssl.setValidatePeerCerts(true);
}
}
defaultPort = 443;
config.addCustomizer(new SecureRequestCustomizer());
c = new ServerConnector(server, null, null, null, 0, acceptors, new SslConnectionFactory(ssl, "http/1.1"), new HttpConnectionFactory(config));
} else if ("proxy-http".equals(u.getScheme())) {
defaultPort = 8080;
config.addCustomizer(new ForwardedRequestCustomizer());
c = newServerConnector(server, acceptors, config);
} else if ("proxy-https".equals(u.getScheme())) {
defaultPort = 8080;
config.addCustomizer(new ForwardedRequestCustomizer());
config.addCustomizer((connector, channelConfig, request) -> {
request.setScheme(HttpScheme.HTTPS.asString());
request.setSecure(true);
});
c = newServerConnector(server, acceptors, config);
} else {
throw new IllegalArgumentException("Protocol '" + u.getScheme() + "' " + " not supported in httpd.listenurl '" + u + "';" + " only 'http', 'https', 'proxy-http, 'proxy-https'" + " are supported");
}
try {
if (u.getHost() == null && (//
u.getAuthority().equals("*") || u.getAuthority().startsWith("*:"))) {
// Bind to all local addresses. Port wasn't parsed right by URI
// due to the illegal host of "*" so replace with a legal name
// and parse the URI.
//
final URI r = new URI(u.toString().replace('*', 'A')).parseServerAuthority();
c.setHost(null);
c.setPort(0 < r.getPort() ? r.getPort() : defaultPort);
} else {
final URI r = u.parseServerAuthority();
c.setHost(r.getHost());
c.setPort(0 <= r.getPort() ? r.getPort() : defaultPort);
}
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid httpd.listenurl " + u, e);
}
c.setInheritChannel(cfg.getBoolean("httpd", "inheritChannel", false));
c.setReuseAddress(reuseAddress);
c.setIdleTimeout(cfg.getTimeUnit("httpd", null, "idleTimeout", 30000L, MILLISECONDS));
connectors[idx] = c;
}
return connectors;
}
Aggregations