use of org.eclipse.jetty.http.HostPortHttpField in project jetty.project by eclipse.
the class AbstractServerTest method newRequest.
protected MetaData.Request newRequest(String method, HttpFields fields) {
String host = "localhost";
int port = connector.getLocalPort();
String authority = host + ":" + port;
return new MetaData.Request(method, HttpScheme.HTTP, new HostPortHttpField(authority), path, HttpVersion.HTTP_2, fields);
}
use of org.eclipse.jetty.http.HostPortHttpField in project jetty.project by eclipse.
the class FlowControlStrategyTest method newRequest.
protected MetaData.Request newRequest(String method, HttpFields fields) {
String host = "localhost";
int port = connector.getLocalPort();
String authority = host + ":" + port;
return new MetaData.Request(method, HttpScheme.HTTP, new HostPortHttpField(authority), "/", HttpVersion.HTTP_2, fields);
}
use of org.eclipse.jetty.http.HostPortHttpField in project jetty.project by eclipse.
the class HTTP2Test method testHostHeader.
@Test
public void testHostHeader() throws Exception {
final String host = "fooBar";
final int port = 1313;
final String authority = host + ":" + port;
start(new HttpServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Assert.assertEquals(host, request.getServerName());
Assert.assertEquals(port, request.getServerPort());
Assert.assertEquals(authority, request.getHeader("Host"));
}
});
Session session = newClient(new Session.Listener.Adapter());
HostPortHttpField hostHeader = new HostPortHttpField(authority);
MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, hostHeader, servletPath, HttpVersion.HTTP_2, new HttpFields());
HeadersFrame frame = new HeadersFrame(metaData, null, true);
final CountDownLatch latch = new CountDownLatch(1);
session.newStream(frame, new Promise.Adapter<>(), new Stream.Listener.Adapter() {
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
MetaData.Response response = (MetaData.Response) frame.getMetaData();
Assert.assertEquals(200, response.getStatus());
if (frame.isEndStream())
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.http.HostPortHttpField in project jetty.project by eclipse.
the class ProxyTest method newRequest.
private MetaData.Request newRequest(String method, String path, HttpFields fields) {
String host = "localhost";
int port = proxyConnector.getLocalPort();
String authority = host + ":" + port;
return new MetaData.Request(method, HttpScheme.HTTP, new HostPortHttpField(authority), path, HttpVersion.HTTP_2, fields);
}
use of org.eclipse.jetty.http.HostPortHttpField in project jetty.project by eclipse.
the class ForwardedRequestCustomizer method customize.
@Override
public void customize(Connector connector, HttpConfiguration config, Request request) {
HttpFields httpFields = request.getHttpFields();
RFC7239 rfc7239 = null;
String forwardedHost = null;
String forwardedServer = null;
String forwardedFor = null;
String forwardedProto = null;
String forwardedHttps = null;
// Do a single pass through the header fields as it is a more efficient single iteration.
for (HttpField field : httpFields) {
String name = field.getName();
if (getForwardedCipherSuiteHeader() != null && getForwardedCipherSuiteHeader().equalsIgnoreCase(name)) {
request.setAttribute("javax.servlet.request.cipher_suite", field.getValue());
if (isSslIsSecure()) {
request.setSecure(true);
request.setScheme(config.getSecureScheme());
}
}
if (getForwardedSslSessionIdHeader() != null && getForwardedSslSessionIdHeader().equalsIgnoreCase(name)) {
request.setAttribute("javax.servlet.request.ssl_session_id", field.getValue());
if (isSslIsSecure()) {
request.setSecure(true);
request.setScheme(config.getSecureScheme());
}
}
if (forwardedHost == null && _forwardedHostHeader != null && _forwardedHostHeader.equalsIgnoreCase(name))
forwardedHost = getLeftMost(field.getValue());
if (forwardedServer == null && _forwardedServerHeader != null && _forwardedServerHeader.equalsIgnoreCase(name))
forwardedServer = getLeftMost(field.getValue());
if (forwardedFor == null && _forwardedForHeader != null && _forwardedForHeader.equalsIgnoreCase(name))
forwardedFor = getLeftMost(field.getValue());
if (forwardedProto == null && _forwardedProtoHeader != null && _forwardedProtoHeader.equalsIgnoreCase(name))
forwardedProto = getLeftMost(field.getValue());
if (forwardedHttps == null && _forwardedHttpsHeader != null && _forwardedHttpsHeader.equalsIgnoreCase(name))
forwardedHttps = getLeftMost(field.getValue());
if (_forwardedHeader != null && _forwardedHeader.equalsIgnoreCase(name)) {
if (rfc7239 == null)
rfc7239 = new RFC7239();
rfc7239.addValue(field.getValue());
}
}
// Handle host header if if not available any RFC7230.by or X-ForwardedServer header
if (_forcedHost != null) {
// Update host header
httpFields.put(_forcedHost);
request.setAuthority(_forcedHost.getHost(), _forcedHost.getPort());
} else if (rfc7239 != null && rfc7239._host != null) {
HostPortHttpField auth = rfc7239._host;
httpFields.put(auth);
request.setAuthority(auth.getHost(), auth.getPort());
} else if (forwardedHost != null) {
HostPortHttpField auth = new HostPortHttpField(forwardedHost);
httpFields.put(auth);
request.setAuthority(auth.getHost(), auth.getPort());
} else if (_proxyAsAuthority) {
if (rfc7239 != null && rfc7239._by != null) {
HostPortHttpField auth = rfc7239._by;
httpFields.put(auth);
request.setAuthority(auth.getHost(), auth.getPort());
} else if (forwardedServer != null) {
request.setAuthority(forwardedServer, request.getServerPort());
}
}
// handle remote end identifier
if (rfc7239 != null && rfc7239._for != null) {
request.setRemoteAddr(InetSocketAddress.createUnresolved(rfc7239._for.getHost(), rfc7239._for.getPort()));
} else if (forwardedFor != null) {
request.setRemoteAddr(InetSocketAddress.createUnresolved(forwardedFor, request.getRemotePort()));
}
// handle protocol identifier
if (rfc7239 != null && rfc7239._proto != null) {
request.setScheme(rfc7239._proto);
if (rfc7239._proto.equals(config.getSecureScheme()))
request.setSecure(true);
} else if (forwardedProto != null) {
request.setScheme(forwardedProto);
if (forwardedProto.equals(config.getSecureScheme()))
request.setSecure(true);
} else if (forwardedHttps != null && ("on".equalsIgnoreCase(forwardedHttps) || "true".equalsIgnoreCase(forwardedHttps))) {
request.setScheme(HttpScheme.HTTPS.asString());
if (HttpScheme.HTTPS.asString().equals(config.getSecureScheme()))
request.setSecure(true);
}
}
Aggregations