Search in sources :

Example 1 with HostPortHttpField

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

Example 2 with HostPortHttpField

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

Example 3 with HostPortHttpField

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));
}
Also used : ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) HttpServlet(javax.servlet.http.HttpServlet) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Promise(org.eclipse.jetty.util.Promise) FuturePromise(org.eclipse.jetty.util.FuturePromise) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) Stream(org.eclipse.jetty.http2.api.Stream) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField) Session(org.eclipse.jetty.http2.api.Session) Test(org.junit.Test)

Example 4 with HostPortHttpField

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);
}
Also used : Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField)

Example 5 with HostPortHttpField

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);
    }
}
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)

Aggregations

HostPortHttpField (org.eclipse.jetty.http.HostPortHttpField)20 HttpField (org.eclipse.jetty.http.HttpField)10 HttpFields (org.eclipse.jetty.http.HttpFields)10 MetaData (org.eclipse.jetty.http.MetaData)10 Test (org.junit.Test)8 ByteBuffer (java.nio.ByteBuffer)7 Parser (org.eclipse.jetty.http2.parser.Parser)7 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)7 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)7 ArrayList (java.util.ArrayList)5 HeaderGenerator (org.eclipse.jetty.http2.generator.HeaderGenerator)5 HpackEncoder (org.eclipse.jetty.http2.hpack.HpackEncoder)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)3 HeadersGenerator (org.eclipse.jetty.http2.generator.HeadersGenerator)3 OutputStream (java.io.OutputStream)2 Socket (java.net.Socket)2 HashMap (java.util.HashMap)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2