Search in sources :

Example 31 with HTTP2Stream

use of org.eclipse.jetty.http2.HTTP2Stream in project vert.x by eclipse.

the class Http2ServerConnection method doSendPush.

private synchronized void doSendPush(int streamId, String host, HttpMethod method, MultiMap headers, String path, StreamPriority streamPriority, Promise<HttpServerResponse> promise) {
    Http2Headers headers_ = new DefaultHttp2Headers();
    headers_.method(method.name());
    headers_.path(path);
    headers_.scheme(isSsl() ? "https" : "http");
    if (host != null) {
        headers_.authority(host);
    }
    if (headers != null) {
        headers.forEach(header -> headers_.add(header.getKey(), header.getValue()));
    }
    handler.writePushPromise(streamId, headers_, new Handler<AsyncResult<Integer>>() {

        @Override
        public void handle(AsyncResult<Integer> ar) {
            if (ar.succeeded()) {
                synchronized (Http2ServerConnection.this) {
                    int promisedStreamId = ar.result();
                    String contentEncoding = HttpUtils.determineContentEncoding(headers_);
                    Http2Stream promisedStream = handler.connection().stream(promisedStreamId);
                    Push push = new Push(context, contentEncoding, method, path, promise);
                    push.priority(streamPriority);
                    push.init(promisedStream);
                    int maxConcurrentStreams = handler.maxConcurrentStreams();
                    if (concurrentStreams < maxConcurrentStreams) {
                        concurrentStreams++;
                        push.complete();
                    } else {
                        pendingPushes.add(push);
                    }
                }
            } else {
                promise.fail(ar.cause());
            }
        }
    });
}
Also used : Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) Http2Stream(io.netty.handler.codec.http2.Http2Stream) AsyncResult(io.vertx.core.AsyncResult)

Aggregations

Http2Stream (io.netty.handler.codec.http2.Http2Stream)26 Http2Exception (io.netty.handler.codec.http2.Http2Exception)10 Test (org.junit.Test)9 Metadata (io.grpc.Metadata)6 Http2StreamVisitor (io.netty.handler.codec.http2.Http2StreamVisitor)6 Status (io.grpc.Status)5 Http2Connection (io.netty.handler.codec.http2.Http2Connection)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 ChannelFuture (io.netty.channel.ChannelFuture)3 Http2LocalFlowController (io.netty.handler.codec.http2.Http2LocalFlowController)3 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)3 FuturePromise (org.eclipse.jetty.util.FuturePromise)3 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)2