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