use of org.glassfish.grizzly.http2.Http2Stream in project jetty.project by eclipse.
the class StreamCloseTest method testPushedStreamIsClosed.
@Test
public void testPushedStreamIsClosed() throws Exception {
final CountDownLatch serverLatch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
PushPromiseFrame pushFrame = new PushPromiseFrame(stream.getId(), 0, newRequest("GET", new HttpFields()));
stream.push(pushFrame, new Promise.Adapter<Stream>() {
@Override
public void succeeded(final Stream pushedStream) {
// When created, pushed stream must be implicitly remotely closed.
Assert.assertTrue(((HTTP2Stream) pushedStream).isRemotelyClosed());
// Send some data with endStream = true.
pushedStream.data(new DataFrame(pushedStream.getId(), ByteBuffer.allocate(16), true), new Callback() {
@Override
public void succeeded() {
Assert.assertTrue(pushedStream.isClosed());
serverLatch.countDown();
}
});
}
}, new Stream.Listener.Adapter());
HeadersFrame response = new HeadersFrame(stream.getId(), new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields()), null, true);
stream.headers(response, Callback.NOOP);
return null;
}
});
Session session = newClient(new Session.Listener.Adapter());
HeadersFrame frame = new HeadersFrame(newRequest("GET", new HttpFields()), null, true);
final CountDownLatch clientLatch = new CountDownLatch(1);
session.newStream(frame, new Promise.Adapter<>(), new Stream.Listener.Adapter() {
@Override
public Stream.Listener onPush(Stream pushedStream, PushPromiseFrame frame) {
Assert.assertTrue(((HTTP2Stream) pushedStream).isLocallyClosed());
return new Adapter() {
@Override
public void onData(Stream pushedStream, DataFrame frame, Callback callback) {
Assert.assertTrue(pushedStream.isClosed());
callback.succeeded();
clientLatch.countDown();
}
};
}
});
Assert.assertTrue(serverLatch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(clientLatch.await(5, TimeUnit.SECONDS));
}
use of org.glassfish.grizzly.http2.Http2Stream in project jetty.project by eclipse.
the class StreamCloseTest method testRequestClosedRemotelyClosesStream.
@Test
public void testRequestClosedRemotelyClosesStream() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
Assert.assertTrue(((HTTP2Stream) stream).isRemotelyClosed());
latch.countDown();
return null;
}
});
Session session = newClient(new Session.Listener.Adapter());
HeadersFrame frame = new HeadersFrame(newRequest("GET", new HttpFields()), null, true);
FuturePromise<Stream> promise = new FuturePromise<>();
session.newStream(frame, promise, null);
Stream stream = promise.get(5, TimeUnit.SECONDS);
Assert.assertTrue(((HTTP2Stream) stream).isLocallyClosed());
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of org.glassfish.grizzly.http2.Http2Stream in project vert.x by eclipse.
the class Http2ClientConnection method onPushPromiseRead.
@Override
public synchronized void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
Http2ClientStream stream = (Http2ClientStream) streams.get(streamId);
if (stream != null) {
Handler<HttpClientRequest> pushHandler = stream.pushHandler();
if (pushHandler != null) {
context.executeFromIO(() -> {
String rawMethod = headers.method().toString();
HttpMethod method = HttpUtils.toVertxMethod(rawMethod);
String uri = headers.path().toString();
String host = headers.authority() != null ? headers.authority().toString() : null;
MultiMap headersMap = new Http2HeadersAdaptor(headers);
Http2Stream promisedStream = handler.connection().stream(promisedStreamId);
int port = remoteAddress().port();
HttpClientRequestPushPromise pushReq = new HttpClientRequestPushPromise(this, promisedStream, http2Pool.client, isSsl(), method, rawMethod, uri, host, port, headersMap);
if (metrics.isEnabled()) {
pushReq.metric(metrics.responsePushed(queueMetric, metric(), localAddress(), remoteAddress(), pushReq));
}
streams.put(promisedStreamId, pushReq.getStream());
pushHandler.handle(pushReq);
});
return;
}
}
handler.writeReset(promisedStreamId, Http2Error.CANCEL.code());
}
use of org.glassfish.grizzly.http2.Http2Stream in project vert.x by eclipse.
the class Http2ClientConnection method createStream.
synchronized HttpClientStream createStream() throws Http2Exception {
Http2Connection conn = handler.connection();
Http2Stream stream = conn.local().createStream(conn.local().incrementAndGetNextStreamId(), false);
boolean writable = handler.encoder().flowController().isWritable(stream);
Http2ClientStream clientStream = new Http2ClientStream(this, stream, writable);
streams.put(clientStream.stream.id(), clientStream);
return clientStream;
}
use of org.glassfish.grizzly.http2.Http2Stream in project Payara by payara.
the class ApplicationPushBuilder method push.
@Override
public void push() {
if (path == null) {
throw new IllegalStateException(rb.getString(LogFacade.NO_PUSH_PATH_EXCEPTION));
}
Http2Stream http2Stream = (Http2Stream) coyoteRequest.getAttribute(Http2Stream.HTTP2_STREAM_ATTRIBUTE);
if (http2Stream == null || !http2Stream.isPushEnabled()) {
return;
}
// modify pathLocal rather than path
String pathLocal = ((path.charAt(0) == '/') ? path : coyoteRequest.getContextPath() + '/' + path);
if (queryString != null) {
pathLocal += ((pathLocal.indexOf('?') != -1) ? '&' + queryString : '?' + queryString);
}
// Session ID (do this before setting the path since it may change it)
if (sessionId != null) {
if (addSessionPathParameter) {
pathLocal = pathLocal + ";" + sessionCookieName + "=" + sessionId;
}
if (addSessionCookie) {
cookies.add(new Cookie(sessionCookieName, sessionId));
}
}
PushEvent.PushEventBuilder pushEventBuilder = PushEvent.builder();
pushEventBuilder.method(method);
pushEventBuilder.headers(headers);
pushEventBuilder.path(pathLocal);
pushEventBuilder.httpRequest(coyoteRequest.getRequest());
coyoteRequest.getContext().notifyDownstream(pushEventBuilder.build());
// Reset for next call
path = null;
for (Header conditionalHeader : CONDITIONAL_HEADERS) {
headers.removeHeader(conditionalHeader);
}
}
Aggregations