use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.
the class HttpClientTransportOverHTTP2Test method testRequestHasHTTP2Version.
@Test
public void testRequestHasHTTP2Version() throws Exception {
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
HttpVersion version = HttpVersion.fromString(request.getProtocol());
response.setStatus(version == HttpVersion.HTTP_2 ? HttpStatus.OK_200 : HttpStatus.INTERNAL_SERVER_ERROR_500);
}
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).onRequestBegin(request -> {
if (request.getVersion() != HttpVersion.HTTP_2)
request.abort(new Exception("Not a HTTP/2 request"));
}).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.
the class HttpClientTransportOverHTTP2Test method testRequestViaForwardHttpProxy.
@Test
public void testRequestViaForwardHttpProxy() throws Exception {
String path = "/path";
String query = "a=b";
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
Assert.assertEquals(path, request.getRequestURI());
Assert.assertEquals(query, request.getQueryString());
}
});
int proxyPort = connector.getLocalPort();
client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyPort));
// Any port will do, just not the same as the proxy.
int serverPort = proxyPort + 1;
ContentResponse response = client.newRequest("localhost", serverPort).path(path + "?" + query).timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.
the class MaxConcurrentStreamsTest method testTwoConcurrentStreamsThirdWaits.
@Test
public void testTwoConcurrentStreamsThirdWaits() throws Exception {
int maxStreams = 2;
long sleep = 1000;
start(maxStreams, new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
sleep(sleep);
}
});
client.setMaxConnectionsPerDestination(1);
primeConnection();
// Send requests up to the max allowed.
for (int i = 0; i < maxStreams; ++i) {
client.newRequest("localhost", connector.getLocalPort()).path("/" + i).send(null);
}
// Send the request in excess.
CountDownLatch latch = new CountDownLatch(1);
String path = "/excess";
client.newRequest("localhost", connector.getLocalPort()).path(path).send(result -> {
if (result.getResponse().getStatus() == HttpStatus.OK_200)
latch.countDown();
});
// The last exchange should remain in the queue.
HttpDestinationOverHTTP2 destination = (HttpDestinationOverHTTP2) client.getDestination("http", "localhost", connector.getLocalPort());
Assert.assertEquals(1, destination.getHttpExchanges().size());
Assert.assertEquals(path, destination.getHttpExchanges().peek().getRequest().getPath());
Assert.assertTrue(latch.await(5 * sleep, TimeUnit.MILLISECONDS));
}
use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.
the class PushedResourcesTest method testPushedResourceCancelled.
@Test
public void testPushedResourceCancelled() throws Exception {
String pushPath = "/secondary";
CountDownLatch latch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
HttpURI pushURI = new HttpURI("http://localhost:" + connector.getLocalPort() + pushPath);
MetaData.Request pushRequest = new MetaData.Request(HttpMethod.GET.asString(), pushURI, HttpVersion.HTTP_2, new HttpFields());
stream.push(new PushPromiseFrame(stream.getId(), 0, pushRequest), new Promise.Adapter<Stream>() {
@Override
public void succeeded(Stream pushStream) {
// Just send the normal response and wait for the reset.
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, HttpStatus.OK_200, new HttpFields());
stream.headers(new HeadersFrame(stream.getId(), response, null, true), Callback.NOOP);
}
}, new Stream.Listener.Adapter() {
@Override
public void onReset(Stream stream, ResetFrame frame) {
latch.countDown();
}
});
return null;
}
});
HttpRequest request = (HttpRequest) client.newRequest("localhost", connector.getLocalPort());
ContentResponse response = request.pushListener((mainRequest, pushedRequest) -> null).timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.
the class SslConnectionFactoryTest method before.
@Before
public void before() throws Exception {
String keystorePath = "src/test/resources/keystore";
File keystoreFile = new File(keystorePath);
if (!keystoreFile.exists())
throw new FileNotFoundException(keystoreFile.getAbsolutePath());
_server = new Server();
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecureScheme("https");
http_config.setSecurePort(8443);
http_config.setOutputBufferSize(32768);
HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
ServerConnector https = _connector = new ServerConnector(_server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
https.setPort(0);
https.setIdleTimeout(30000);
_server.addConnector(https);
_server.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setStatus(200);
response.getWriter().write("url=" + request.getRequestURI() + "\nhost=" + request.getServerName());
response.flushBuffer();
}
});
_server.start();
_port = https.getLocalPort();
}
Aggregations