use of org.eclipse.jetty.http2.api.Stream in project jetty.project by eclipse.
the class HttpChannelOverHTTP2 method commit.
@Override
protected void commit(MetaData.Response info) {
super.commit(info);
if (LOG.isDebugEnabled()) {
Stream stream = getStream();
LOG.debug("HTTP2 Commit Response #{}/{}:{}{} {} {}{}{}", stream.getId(), Integer.toHexString(stream.getSession().hashCode()), System.lineSeparator(), info.getHttpVersion(), info.getStatus(), info.getReason(), System.lineSeparator(), info.getFields());
}
}
use of org.eclipse.jetty.http2.api.Stream in project jetty.project by eclipse.
the class HttpChannelOverHTTP2 method onRequestTrailers.
public void onRequestTrailers(HeadersFrame frame) {
HttpFields trailers = frame.getMetaData().getFields();
onTrailers(trailers);
onRequestComplete();
if (LOG.isDebugEnabled()) {
Stream stream = getStream();
LOG.debug("HTTP2 Request #{}/{}, trailers:{}{}", stream.getId(), Integer.toHexString(stream.getSession().hashCode()), System.lineSeparator(), trailers);
}
}
use of org.eclipse.jetty.http2.api.Stream in project jetty.project by eclipse.
the class CloseTest method testClientAbruptlyClosesConnection.
@Test
public void testClientAbruptlyClosesConnection() throws Exception {
final CountDownLatch closeLatch = new CountDownLatch(1);
final AtomicReference<Session> sessionRef = new AtomicReference<>();
startServer(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
try {
sessionRef.set(stream.getSession());
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
// Reply with HEADERS.
stream.headers(new HeadersFrame(stream.getId(), response, null, true), Callback.NOOP);
closeLatch.await(5, TimeUnit.SECONDS);
return null;
} catch (InterruptedException x) {
return null;
}
}
});
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.control(lease, new PrefaceFrame());
generator.control(lease, new SettingsFrame(new HashMap<>(), false));
MetaData.Request metaData = newRequest("GET", new HttpFields());
generator.control(lease, new HeadersFrame(1, metaData, null, true));
try (Socket client = new Socket("localhost", connector.getLocalPort())) {
OutputStream output = client.getOutputStream();
for (ByteBuffer buffer : lease.getByteBuffers()) {
output.write(BufferUtil.toArray(buffer));
}
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {
@Override
public void onHeaders(HeadersFrame frame) {
try {
// Close the connection just after
// receiving the response headers.
client.close();
closeLatch.countDown();
} catch (IOException x) {
throw new RuntimeIOException(x);
}
}
}, 4096, 8192);
parseResponse(client, parser);
// We need to give some time to the server to receive and process the TCP FIN.
Thread.sleep(1000);
Session session = sessionRef.get();
Assert.assertTrue(session.isClosed());
Assert.assertTrue(((HTTP2Session) session).isDisconnected());
}
}
use of org.eclipse.jetty.http2.api.Stream in project jetty.project by eclipse.
the class CloseTest method testClientSendsGoAwayButDoesNotCloseConnectionServerCloses.
@Test
public void testClientSendsGoAwayButDoesNotCloseConnectionServerCloses() throws Exception {
final AtomicReference<Session> sessionRef = new AtomicReference<>();
startServer(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
sessionRef.set(stream.getSession());
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
stream.headers(new HeadersFrame(stream.getId(), response, null, true), Callback.NOOP);
return null;
}
});
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.control(lease, new PrefaceFrame());
generator.control(lease, new SettingsFrame(new HashMap<>(), false));
MetaData.Request metaData = newRequest("GET", new HttpFields());
generator.control(lease, new HeadersFrame(1, metaData, null, true));
generator.control(lease, new GoAwayFrame(1, ErrorCode.NO_ERROR.code, "OK".getBytes("UTF-8")));
try (Socket client = new Socket("localhost", connector.getLocalPort())) {
OutputStream output = client.getOutputStream();
for (ByteBuffer buffer : lease.getByteBuffers()) {
output.write(BufferUtil.toArray(buffer));
}
// Don't close the connection; the server should close.
final CountDownLatch responseLatch = new CountDownLatch(1);
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {
@Override
public void onHeaders(HeadersFrame frame) {
// Even if we sent the GO_AWAY immediately after the
// HEADERS, the server is able to send us the response.
responseLatch.countDown();
}
}, 4096, 8192);
parseResponse(client, parser);
Assert.assertTrue(responseLatch.await(5, TimeUnit.SECONDS));
// Wait for the server to close.
Thread.sleep(1000);
// Client received the TCP FIN from server.
Assert.assertEquals(-1, client.getInputStream().read());
// Server is closed.
Session session = sessionRef.get();
Assert.assertTrue(session.isClosed());
Assert.assertTrue(((HTTP2Session) session).isDisconnected());
}
}
use of org.eclipse.jetty.http2.api.Stream 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));
}
Aggregations