use of org.eclipse.jetty.http.HttpFields 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);
}
}
use of org.eclipse.jetty.http.HttpFields in project jetty.project by eclipse.
the class HttpChannel method onRequest.
public void onRequest(MetaData.Request request) {
_requests.incrementAndGet();
_request.setTimeStamp(System.currentTimeMillis());
HttpFields fields = _response.getHttpFields();
if (_configuration.getSendDateHeader() && !fields.contains(HttpHeader.DATE))
fields.put(_connector.getServer().getDateField());
long idleTO = _configuration.getIdleTimeout();
_oldIdleTimeout = getIdleTimeout();
if (idleTO >= 0 && _oldIdleTimeout != idleTO)
setIdleTimeout(idleTO);
_request.setMetaData(request);
if (LOG.isDebugEnabled())
LOG.debug("REQUEST for {} on {}{}{} {} {}{}{}", request.getURIString(), this, System.lineSeparator(), request.getMethod(), request.getURIString(), request.getHttpVersion(), System.lineSeparator(), request.getFields());
}
use of org.eclipse.jetty.http.HttpFields in project jetty.project by eclipse.
the class MsieSslRuleTest method testWin2kWithIE5.
@Test
public void testWin2kWithIE5() throws Exception {
HttpFields fields = _request.getHttpFields();
fields.add("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.0)");
String result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
assertEquals(_request.getRequestURI(), result);
assertEquals(HttpHeaderValue.CLOSE.asString(), _response.getHeader(HttpHeader.CONNECTION.asString()));
fields.add("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
assertEquals(_request.getRequestURI(), result);
assertEquals(HttpHeaderValue.CLOSE.asString(), _response.getHeader(HttpHeader.CONNECTION.asString()));
fields.add("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");
result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
assertEquals(_request.getRequestURI(), result);
assertEquals(HttpHeaderValue.CLOSE.asString(), _response.getHeader(HttpHeader.CONNECTION.asString()));
}
use of org.eclipse.jetty.http.HttpFields in project jetty.project by eclipse.
the class MsieSslRuleTest method testWinXpWithIE5.
@Test
public void testWinXpWithIE5() throws Exception {
HttpFields fields = _request.getHttpFields();
fields.add("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.1)");
String result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
assertEquals(_request.getRequestURI(), result);
assertEquals(HttpHeaderValue.CLOSE.asString(), _response.getHeader(HttpHeader.CONNECTION.asString()));
fields.add("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.1)");
result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
assertEquals(_request.getRequestURI(), result);
assertEquals(HttpHeaderValue.CLOSE.asString(), _response.getHeader(HttpHeader.CONNECTION.asString()));
fields.add("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)");
result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
assertEquals(_request.getRequestURI(), result);
assertEquals(HttpHeaderValue.CLOSE.asString(), _response.getHeader(HttpHeader.CONNECTION.asString()));
}
use of org.eclipse.jetty.http.HttpFields in project jetty.project by eclipse.
the class MsieSslRuleTest method testWinXpWithIE6.
@Test
public void testWinXpWithIE6() throws Exception {
HttpFields fields = _request.getHttpFields();
fields.add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
String result = _rule.matchAndApply(_request.getRequestURI(), _request, _response);
assertEquals(null, result);
assertEquals(null, _response.getHeader(HttpHeader.CONNECTION.asString()));
}
Aggregations