Search in sources :

Example 11 with Http2Stream

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));
}
Also used : ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) HTTP2Stream(org.eclipse.jetty.http2.HTTP2Stream) DataFrame(org.eclipse.jetty.http2.frames.DataFrame) CountDownLatch(java.util.concurrent.CountDownLatch) PushPromiseFrame(org.eclipse.jetty.http2.frames.PushPromiseFrame) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) Promise(org.eclipse.jetty.util.Promise) FuturePromise(org.eclipse.jetty.util.FuturePromise) Callback(org.eclipse.jetty.util.Callback) HttpFields(org.eclipse.jetty.http.HttpFields) HTTP2Stream(org.eclipse.jetty.http2.HTTP2Stream) Stream(org.eclipse.jetty.http2.api.Stream) ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) HTTP2Session(org.eclipse.jetty.http2.HTTP2Session) Session(org.eclipse.jetty.http2.api.Session) Test(org.junit.Test)

Example 12 with Http2Stream

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));
}
Also used : ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) HTTP2Stream(org.eclipse.jetty.http2.HTTP2Stream) FuturePromise(org.eclipse.jetty.util.FuturePromise) CountDownLatch(java.util.concurrent.CountDownLatch) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) HttpFields(org.eclipse.jetty.http.HttpFields) HTTP2Stream(org.eclipse.jetty.http2.HTTP2Stream) Stream(org.eclipse.jetty.http2.api.Stream) ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) HTTP2Session(org.eclipse.jetty.http2.HTTP2Session) Session(org.eclipse.jetty.http2.api.Session) Test(org.junit.Test)

Example 13 with Http2Stream

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());
}
Also used : MultiMap(io.vertx.core.MultiMap) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Http2Stream(io.netty.handler.codec.http2.Http2Stream) HttpMethod(io.vertx.core.http.HttpMethod)

Example 14 with Http2Stream

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;
}
Also used : Http2Connection(io.netty.handler.codec.http2.Http2Connection) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 15 with Http2Stream

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);
    }
}
Also used : Cookie(org.glassfish.grizzly.http.Cookie) PushEvent(org.glassfish.grizzly.http.server.http2.PushEvent) Header(org.glassfish.grizzly.http.util.Header) Http2Stream(org.glassfish.grizzly.http2.Http2Stream)

Aggregations

Http2Stream (io.netty.handler.codec.http2.Http2Stream)21 Http2Exception (io.netty.handler.codec.http2.Http2Exception)8 Test (org.junit.Test)8 Http2StreamVisitor (io.netty.handler.codec.http2.Http2StreamVisitor)5 Metadata (io.grpc.Metadata)4 Http2LocalFlowController (io.netty.handler.codec.http2.Http2LocalFlowController)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HttpFields (org.eclipse.jetty.http.HttpFields)4 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)4 HTTP2Stream (org.eclipse.jetty.http2.HTTP2Stream)4 Session (org.eclipse.jetty.http2.api.Session)4 Stream (org.eclipse.jetty.http2.api.Stream)4 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)4 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)4 FuturePromise (org.eclipse.jetty.util.FuturePromise)4 Status (io.grpc.Status)2 ByteBuf (io.netty.buffer.ByteBuf)2 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)2