Search in sources :

Example 66 with HttpFields

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);
    }
}
Also used : HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField) HttpField(org.eclipse.jetty.http.HttpField) HttpFields(org.eclipse.jetty.http.HttpFields) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField)

Example 67 with HttpFields

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());
}
Also used : HttpFields(org.eclipse.jetty.http.HttpFields)

Example 68 with HttpFields

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()));
}
Also used : HttpFields(org.eclipse.jetty.http.HttpFields) Test(org.junit.Test)

Example 69 with HttpFields

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()));
}
Also used : HttpFields(org.eclipse.jetty.http.HttpFields) Test(org.junit.Test)

Example 70 with HttpFields

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()));
}
Also used : HttpFields(org.eclipse.jetty.http.HttpFields) Test(org.junit.Test)

Aggregations

HttpFields (org.eclipse.jetty.http.HttpFields)172 Test (org.junit.Test)142 MetaData (org.eclipse.jetty.http.MetaData)117 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)105 CountDownLatch (java.util.concurrent.CountDownLatch)96 Stream (org.eclipse.jetty.http2.api.Stream)93 Session (org.eclipse.jetty.http2.api.Session)89 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)79 FuturePromise (org.eclipse.jetty.util.FuturePromise)69 HttpServletResponse (javax.servlet.http.HttpServletResponse)59 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)55 Callback (org.eclipse.jetty.util.Callback)53 ByteBuffer (java.nio.ByteBuffer)52 Promise (org.eclipse.jetty.util.Promise)49 HttpServletRequest (javax.servlet.http.HttpServletRequest)46 IOException (java.io.IOException)42 ServletException (javax.servlet.ServletException)39 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)37 HttpServlet (javax.servlet.http.HttpServlet)33 HashMap (java.util.HashMap)32