use of org.eclipse.jetty.http2.api.Stream in project jetty.project by eclipse.
the class HTTP2Test method testRequestNoContentResponseEmptyContent.
@Test
public void testRequestNoContentResponseEmptyContent() throws Exception {
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, HttpStatus.OK_200, new HttpFields());
stream.headers(new HeadersFrame(stream.getId(), response, null, false), new Callback() {
@Override
public void succeeded() {
stream.data(new DataFrame(stream.getId(), BufferUtil.EMPTY_BUFFER, true), NOOP);
}
});
return null;
}
});
Session session = newClient(new Session.Listener.Adapter());
HttpFields fields = new HttpFields();
MetaData.Request metaData = newRequest("GET", fields);
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) {
Assert.assertFalse(frame.isEndStream());
Assert.assertEquals(stream.getId(), frame.getStreamId());
MetaData.Response response = (MetaData.Response) frame.getMetaData();
Assert.assertEquals(200, response.getStatus());
}
@Override
public void onData(Stream stream, DataFrame frame, Callback callback) {
Assert.assertTrue(frame.isEndStream());
callback.succeeded();
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.http2.api.Stream in project jetty.project by eclipse.
the class IdleTimeoutTest method testServerEnforcingIdleTimeout.
@Test
public void testServerEnforcingIdleTimeout() throws Exception {
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame requestFrame) {
stream.setIdleTimeout(10 * idleTimeout);
MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true);
stream.headers(responseFrame, Callback.NOOP);
return null;
}
});
connector.setIdleTimeout(idleTimeout);
final CountDownLatch latch = new CountDownLatch(1);
Session session = newClient(new Session.Listener.Adapter() {
@Override
public void onClose(Session session, GoAwayFrame frame) {
latch.countDown();
}
});
MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(metaData, null, true);
session.newStream(requestFrame, new Promise.Adapter<Stream>() {
@Override
public void succeeded(Stream stream) {
stream.setIdleTimeout(10 * idleTimeout);
}
}, new Stream.Listener.Adapter());
Assert.assertTrue(latch.await(5 * idleTimeout, TimeUnit.MILLISECONDS));
}
use of org.eclipse.jetty.http2.api.Stream in project jetty.project by eclipse.
the class IdleTimeoutTest method testServerEnforcingIdleTimeoutWithUnrespondedStream.
@Test
public void testServerEnforcingIdleTimeoutWithUnrespondedStream() throws Exception {
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
stream.setIdleTimeout(10 * idleTimeout);
return null;
}
});
connector.setIdleTimeout(idleTimeout);
final CountDownLatch latch = new CountDownLatch(1);
Session session = newClient(new Session.Listener.Adapter() {
@Override
public void onClose(Session session, GoAwayFrame frame) {
latch.countDown();
}
});
// The request is not replied, and the server should idle timeout.
MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(metaData, null, true);
session.newStream(requestFrame, new Promise.Adapter<Stream>() {
@Override
public void succeeded(Stream stream) {
stream.setIdleTimeout(10 * idleTimeout);
}
}, new Stream.Listener.Adapter());
Assert.assertTrue(latch.await(5 * idleTimeout, TimeUnit.MILLISECONDS));
}
use of org.eclipse.jetty.http2.api.Stream in project jetty.project by eclipse.
the class IdleTimeoutTest method testClientEnforcingIdleTimeoutWithUnrespondedStream.
@Test
public void testClientEnforcingIdleTimeoutWithUnrespondedStream() throws Exception {
final CountDownLatch closeLatch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
stream.setIdleTimeout(10 * idleTimeout);
return null;
}
@Override
public void onClose(Session session, GoAwayFrame frame) {
closeLatch.countDown();
}
});
client.setIdleTimeout(idleTimeout);
Session session = newClient(new Session.Listener.Adapter());
MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(metaData, null, true);
session.newStream(requestFrame, new Promise.Adapter<Stream>() {
@Override
public void succeeded(Stream stream) {
stream.setIdleTimeout(10 * idleTimeout);
}
}, new Stream.Listener.Adapter());
Assert.assertTrue(closeLatch.await(5 * idleTimeout, TimeUnit.MILLISECONDS));
}
use of org.eclipse.jetty.http2.api.Stream in project jetty.project by eclipse.
the class JDK9HTTP2Client method main.
public static void main(String[] args) throws Exception {
HTTP2Client client = new HTTP2Client();
SslContextFactory sslContextFactory = new SslContextFactory(true);
client.addBean(sslContextFactory);
client.start();
String host = "localhost";
int port = 8443;
FuturePromise<Session> sessionPromise = new FuturePromise<>();
client.connect(sslContextFactory, new InetSocketAddress(host, port), new Session.Listener.Adapter(), sessionPromise);
Session session = sessionPromise.get(555, TimeUnit.SECONDS);
HttpFields requestFields = new HttpFields();
requestFields.put("User-Agent", client.getClass().getName() + "/" + Jetty.VERSION);
MetaData.Request metaData = new MetaData.Request("GET", new HttpURI("https://" + host + ":" + port + "/"), HttpVersion.HTTP_2, requestFields);
HeadersFrame headersFrame = new HeadersFrame(metaData, null, true);
CountDownLatch latch = new CountDownLatch(1);
session.newStream(headersFrame, new Promise.Adapter<>(), new Stream.Listener.Adapter() {
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
System.err.println(frame);
if (frame.isEndStream())
latch.countDown();
}
@Override
public void onData(Stream stream, DataFrame frame, Callback callback) {
System.err.println(frame);
callback.succeeded();
if (frame.isEndStream())
latch.countDown();
}
});
latch.await(5, TimeUnit.SECONDS);
client.stop();
}
Aggregations