use of org.eclipse.jetty.http2.frames.HeadersFrame in project jetty.project by eclipse.
the class TrailersTest method testTrailersSentByClient.
@Test
public void testTrailersSentByClient() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
MetaData.Request request = (MetaData.Request) frame.getMetaData();
Assert.assertFalse(frame.isEndStream());
Assert.assertTrue(request.getFields().containsKey("X-Request"));
return new Stream.Listener.Adapter() {
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
MetaData trailer = frame.getMetaData();
Assert.assertTrue(frame.isEndStream());
Assert.assertTrue(trailer.getFields().containsKey("X-Trailer"));
latch.countDown();
}
};
}
});
Session session = newClient(new Session.Listener.Adapter());
HttpFields requestFields = new HttpFields();
requestFields.put("X-Request", "true");
MetaData.Request request = newRequest("GET", requestFields);
HeadersFrame requestFrame = new HeadersFrame(request, null, false);
FuturePromise<Stream> streamPromise = new FuturePromise<>();
session.newStream(requestFrame, streamPromise, new Stream.Listener.Adapter());
Stream stream = streamPromise.get(5, TimeUnit.SECONDS);
// Send the trailers.
HttpFields trailerFields = new HttpFields();
trailerFields.put("X-Trailer", "true");
MetaData trailers = new MetaData(HttpVersion.HTTP_2, trailerFields);
HeadersFrame trailerFrame = new HeadersFrame(stream.getId(), trailers, null, true);
stream.headers(trailerFrame, Callback.NOOP);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.http2.frames.HeadersFrame in project jetty.project by eclipse.
the class ContinuationBodyParser method onHeaders.
private void onHeaders() {
ByteBuffer headerBlock = headerBlockFragments.complete();
MetaData metaData = headerBlockParser.parse(headerBlock, headerBlock.remaining());
HeadersFrame frame = new HeadersFrame(getStreamId(), metaData, headerBlockFragments.getPriorityFrame(), headerBlockFragments.isEndStream());
notifyHeaders(frame);
}
use of org.eclipse.jetty.http2.frames.HeadersFrame in project jetty.project by eclipse.
the class HeadersBodyParser method onHeaders.
private void onHeaders(int parentStreamId, int weight, boolean exclusive, MetaData metaData) {
PriorityFrame priorityFrame = null;
if (hasFlag(Flags.PRIORITY))
priorityFrame = new PriorityFrame(getStreamId(), parentStreamId, weight, exclusive);
HeadersFrame frame = new HeadersFrame(getStreamId(), metaData, priorityFrame, isEndStream());
notifyHeaders(frame);
}
use of org.eclipse.jetty.http2.frames.HeadersFrame in project jetty.project by eclipse.
the class HttpClientTransportOverHTTP2Test method testRequestAbortSendsResetFrame.
@Test
public void testRequestAbortSendsResetFrame() throws Exception {
CountDownLatch resetLatch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
return new Stream.Listener.Adapter() {
@Override
public void onReset(Stream stream, ResetFrame frame) {
resetLatch.countDown();
}
};
}
});
try {
client.newRequest("localhost", connector.getLocalPort()).onRequestCommit(request -> request.abort(new Exception("explicitly_aborted_by_test"))).send();
Assert.fail();
} catch (ExecutionException x) {
Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
}
}
use of org.eclipse.jetty.http2.frames.HeadersFrame in project jetty.project by eclipse.
the class HttpClientTransportOverHTTP2Test method testConnectionIdleTimeoutSendsResetFrame.
@Test
public void testConnectionIdleTimeoutSendsResetFrame() throws Exception {
long idleTimeout = 1000;
CountDownLatch resetLatch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
return new Stream.Listener.Adapter() {
@Override
public void onReset(Stream stream, ResetFrame frame) {
resetLatch.countDown();
}
};
}
});
client.stop();
client.setIdleTimeout(idleTimeout);
client.start();
try {
client.newRequest("localhost", connector.getLocalPort()).idleTimeout(2 * idleTimeout, TimeUnit.MILLISECONDS).send();
Assert.fail();
} catch (ExecutionException e) {
// Expected.
}
Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
}
Aggregations