Search in sources :

Example 21 with HttpURI

use of org.eclipse.jetty.http.HttpURI in project jetty.project by eclipse.

the class Request method getServerPort.

/* ------------------------------------------------------------ */
/*
     * @see javax.servlet.ServletRequest#getServerPort()
     */
@Override
public int getServerPort() {
    MetaData.Request metadata = _metaData;
    HttpURI uri = metadata == null ? null : metadata.getURI();
    int port = (uri == null || uri.getHost() == null) ? findServerPort() : uri.getPort();
    // If no port specified, return the default port for the scheme
    if (port <= 0) {
        if (getScheme().equalsIgnoreCase(URIUtil.HTTPS))
            return 443;
        return 80;
    }
    // return a specific port
    return port;
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpURI(org.eclipse.jetty.http.HttpURI)

Example 22 with HttpURI

use of org.eclipse.jetty.http.HttpURI in project jetty.project by eclipse.

the class HttpSenderOverHTTP2 method sendHeaders.

@Override
protected void sendHeaders(HttpExchange exchange, final HttpContent content, final Callback callback) {
    Request request = exchange.getRequest();
    String path = relativize(request.getPath());
    HttpURI uri = new HttpURI(request.getScheme(), request.getHost(), request.getPort(), path, null, request.getQuery(), null);
    MetaData.Request metaData = new MetaData.Request(request.getMethod(), uri, HttpVersion.HTTP_2, request.getHeaders());
    HeadersFrame headersFrame = new HeadersFrame(metaData, null, !content.hasContent());
    HttpChannelOverHTTP2 channel = getHttpChannel();
    Promise<Stream> promise = new Promise<Stream>() {

        @Override
        public void succeeded(Stream stream) {
            getHttpChannel().setStream(stream);
            stream.setIdleTimeout(request.getIdleTimeout());
            if (content.hasContent() && !expects100Continue(request)) {
                boolean advanced = content.advance();
                boolean lastContent = content.isLast();
                if (advanced || lastContent) {
                    DataFrame dataFrame = new DataFrame(stream.getId(), content.getByteBuffer(), lastContent);
                    stream.data(dataFrame, callback);
                    return;
                }
            }
            callback.succeeded();
        }

        @Override
        public void failed(Throwable failure) {
            callback.failed(failure);
        }
    };
    // TODO optimize the send of HEADERS and DATA frames.
    channel.getSession().newStream(headersFrame, promise, channel.getStreamListener());
}
Also used : Request(org.eclipse.jetty.client.api.Request) DataFrame(org.eclipse.jetty.http2.frames.DataFrame) HttpURI(org.eclipse.jetty.http.HttpURI) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) Promise(org.eclipse.jetty.util.Promise) MetaData(org.eclipse.jetty.http.MetaData) Stream(org.eclipse.jetty.http2.api.Stream)

Example 23 with HttpURI

use of org.eclipse.jetty.http.HttpURI in project gocd by gocd.

the class BackupFilterTest method request.

private Request request(HttpMethod method, String contentType, String uri) {
    Request request = new Request(mock(HttpChannel.class), mock(HttpInput.class));
    request.setContentType(contentType);
    request.setMethod(method, method.asString());
    request.setUri(new HttpURI(uri));
    return request;
}
Also used : HttpInput(org.eclipse.jetty.server.HttpInput) Request(org.eclipse.jetty.server.Request) HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpURI(org.eclipse.jetty.http.HttpURI)

Example 24 with HttpURI

use of org.eclipse.jetty.http.HttpURI in project gocd by gocd.

the class DeploymentContextWriterTest method shouldSetShouldRedirectToFalseWhenSecureSiteURLIsNotSetAndSiteUrlIsNonHTTPS.

@Test
public void shouldSetShouldRedirectToFalseWhenSecureSiteURLIsNotSetAndSiteUrlIsNonHTTPS() throws URISyntaxException {
    final ServerConfigService serverConfigService = mock(ServerConfigService.class);
    when(serverConfigService.hasAnyUrlConfigured()).thenReturn(true);
    when(serverConfigService.siteUrlFor("http://url:8153/go/admin?tab=oAuth", true)).thenReturn("http://url:8153/go/admin?tab=oAuth");
    Request req = new Request(mock(HttpChannel.class), mock(HttpInput.class));
    req.setUri(new HttpURI("/go/admin?tab=oAuth"));
    req.setServerName("url");
    req.setServerPort(8153);
    //req.setProtocol("http");
    DeploymentContextWriter writer = new DeploymentContextWriter() {

        @Override
        protected BaseUrlProvider getBaseUrlProvider(HttpServletRequest req) {
            return serverConfigService;
        }
    };
    writer.writeSecureSiteUrl(req);
    assertThat(req.getAttribute("secure_site"), is(nullValue()));
    assertThat(req.getAttribute("force_ssl"), is(nullValue()));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConfigService(com.thoughtworks.go.server.service.ServerConfigService) HttpInput(org.eclipse.jetty.server.HttpInput) Request(org.eclipse.jetty.server.Request) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpURI(org.eclipse.jetty.http.HttpURI) Test(org.junit.Test)

Aggregations

HttpURI (org.eclipse.jetty.http.HttpURI)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Request (org.eclipse.jetty.server.Request)10 MetaData (org.eclipse.jetty.http.MetaData)9 HttpFields (org.eclipse.jetty.http.HttpFields)8 Stream (org.eclipse.jetty.http2.api.Stream)7 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)7 Test (org.junit.Test)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 InetSocketAddress (java.net.InetSocketAddress)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Session (org.eclipse.jetty.http2.api.Session)5 FuturePromise (org.eclipse.jetty.util.FuturePromise)5 Promise (org.eclipse.jetty.util.Promise)5 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)4 HttpChannel (org.eclipse.jetty.server.HttpChannel)4 HttpInput (org.eclipse.jetty.server.HttpInput)4 ServerConfigService (com.thoughtworks.go.server.service.ServerConfigService)3 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)3 Callback (org.eclipse.jetty.util.Callback)3