Search in sources :

Example 6 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.

the class NettyClientHandlerTest method receiveMaxConcurrentStreams.

private void receiveMaxConcurrentStreams(int max) throws Exception {
    ByteBuf serializedSettings = serializeSettings(new Http2Settings().maxConcurrentStreams(max));
    channelRead(serializedSettings);
}
Also used : Http2Settings(io.netty.handler.codec.http2.Http2Settings) ByteBuf(io.netty.buffer.ByteBuf)

Example 7 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project vert.x by eclipse.

the class Http2ServerTest method testServerInitialSettings.

@Test
public void testServerInitialSettings() throws Exception {
    io.vertx.core.http.Http2Settings settings = TestUtils.randomHttp2Settings();
    server.close();
    server = vertx.createHttpServer(serverOptions.setInitialSettings(settings));
    server.requestHandler(req -> fail());
    startServer();
    TestClient client = new TestClient();
    ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
        request.decoder.frameListener(new Http2FrameAdapter() {

            @Override
            public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings newSettings) throws Http2Exception {
                vertx.runOnContext(v -> {
                    assertEquals((Long) settings.getHeaderTableSize(), newSettings.headerTableSize());
                    assertEquals((Long) settings.getMaxConcurrentStreams(), newSettings.maxConcurrentStreams());
                    assertEquals((Integer) settings.getInitialWindowSize(), newSettings.initialWindowSize());
                    assertEquals((Integer) settings.getMaxFrameSize(), newSettings.maxFrameSize());
                    assertEquals((Long) settings.getMaxHeaderListSize(), newSettings.maxHeaderListSize());
                    assertEquals(settings.get(''), newSettings.get(''));
                    testComplete();
                });
            }
        });
    });
    fut.sync();
    await();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) HttpServer(io.vertx.core.http.HttpServer) MultiMap(io.vertx.core.MultiMap) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Context(io.vertx.core.Context) Unpooled(io.netty.buffer.Unpooled) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) Map(java.util.Map) ApplicationProtocolNegotiationHandler(io.netty.handler.ssl.ApplicationProtocolNegotiationHandler) ReadStream(io.vertx.core.streams.ReadStream) AbstractHttp2ConnectionHandlerBuilder(io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder) Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) StreamResetException(io.vertx.core.http.StreamResetException) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ChannelInitializer(io.netty.channel.ChannelInitializer) Http2Flags(io.netty.handler.codec.http2.Http2Flags) Set(java.util.Set) ChannelPipeline(io.netty.channel.ChannelPipeline) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) Future(io.vertx.core.Future) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) SslHandler(io.netty.handler.ssl.SslHandler) Http2Headers(io.netty.handler.codec.http2.Http2Headers) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Http2Error(io.netty.handler.codec.http2.Http2Error) HttpClient(io.vertx.core.http.HttpClient) NetSocket(io.vertx.core.net.NetSocket) Trust(io.vertx.test.core.tls.Trust) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Http2EventAdapter(io.netty.handler.codec.http2.Http2EventAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ByteBuf(io.netty.buffer.ByteBuf) WriteStream(io.vertx.core.streams.WriteStream) Http2Stream(io.netty.handler.codec.http2.Http2Stream) BiConsumer(java.util.function.BiConsumer) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) EventLoopGroup(io.netty.channel.EventLoopGroup) VertxInternal(io.vertx.core.impl.VertxInternal) ClosedChannelException(java.nio.channels.ClosedChannelException) Vertx(io.vertx.core.Vertx) FileOutputStream(java.io.FileOutputStream) ApplicationProtocolNames(io.netty.handler.ssl.ApplicationProtocolNames) Test(org.junit.Test) IOException(java.io.IOException) SSLHelper(io.vertx.core.net.impl.SSLHelper) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) Http2Settings(io.netty.handler.codec.http2.Http2Settings) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Bootstrap(io.netty.bootstrap.Bootstrap) AtomicLong(java.util.concurrent.atomic.AtomicLong) Http2Connection(io.netty.handler.codec.http2.Http2Connection) HttpMethod(io.vertx.core.http.HttpMethod) HttpUtils(io.vertx.core.http.impl.HttpUtils) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Handler(io.vertx.core.Handler) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) Http2Exception(io.netty.handler.codec.http2.Http2Exception) Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) Http2Settings(io.netty.handler.codec.http2.Http2Settings) Test(org.junit.Test)

Example 8 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project vert.x by eclipse.

the class HttpUtils method fromVertxSettings.

public static Http2Settings fromVertxSettings(io.vertx.core.http.Http2Settings settings) {
    Http2Settings converted = new Http2Settings();
    converted.pushEnabled(settings.isPushEnabled());
    converted.maxFrameSize(settings.getMaxFrameSize());
    converted.initialWindowSize(settings.getInitialWindowSize());
    converted.headerTableSize(settings.getHeaderTableSize());
    converted.maxConcurrentStreams(settings.getMaxConcurrentStreams());
    converted.maxHeaderListSize(settings.getMaxHeaderListSize());
    if (settings.getExtraSettings() != null) {
        settings.getExtraSettings().forEach((key, value) -> {
            converted.put((char) (int) key, value);
        });
    }
    return converted;
}
Also used : Http2Settings(io.netty.handler.codec.http2.Http2Settings)

Example 9 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project vert.x by eclipse.

the class VertxHttp2ClientUpgradeCodec method setUpgradeHeaders.

@Override
public Collection<CharSequence> setUpgradeHeaders(ChannelHandlerContext ctx, HttpRequest upgradeRequest) {
    Http2Settings nettySettings = new Http2Settings();
    HttpUtils.fromVertxInitialSettings(false, settings, nettySettings);
    Buffer buf = Buffer.buffer();
    for (CharObjectMap.PrimitiveEntry<Long> entry : nettySettings.entries()) {
        buf.appendUnsignedShort(entry.key());
        buf.appendUnsignedInt(entry.value());
    }
    String encodedSettings = new String(java.util.Base64.getUrlEncoder().encode(buf.getBytes()), UTF_8);
    upgradeRequest.headers().set(HTTP_UPGRADE_SETTINGS_HEADER, encodedSettings);
    return UPGRADE_HEADERS;
}
Also used : Buffer(io.vertx.core.buffer.Buffer) Http2Settings(io.netty.handler.codec.http2.Http2Settings) CharObjectMap(io.netty.util.collection.CharObjectMap)

Example 10 with Http2Settings

use of io.netty.handler.codec.http2.Http2Settings in project vert.x by eclipse.

the class Http2ConnectionBase method updateSettings.

@Override
public HttpConnection updateSettings(io.vertx.core.http.Http2Settings settings, @Nullable Handler<AsyncResult<Void>> completionHandler) {
    Http2Settings settingsUpdate = HttpUtils.fromVertxSettings(settings);
    updateSettings(settingsUpdate, completionHandler);
    return this;
}
Also used : Http2Settings(io.netty.handler.codec.http2.Http2Settings)

Aggregations

Http2Settings (io.netty.handler.codec.http2.Http2Settings)12 ByteBuf (io.netty.buffer.ByteBuf)7 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 Test (org.junit.Test)5 Http2ConnectionDecoder (io.netty.handler.codec.http2.Http2ConnectionDecoder)4 Buffer (io.vertx.core.buffer.Buffer)4 ChannelFuture (io.netty.channel.ChannelFuture)3 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)3 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)3 Http2Connection (io.netty.handler.codec.http2.Http2Connection)3 Http2ConnectionEncoder (io.netty.handler.codec.http2.Http2ConnectionEncoder)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Bootstrap (io.netty.bootstrap.Bootstrap)2 Unpooled (io.netty.buffer.Unpooled)2 Channel (io.netty.channel.Channel)2 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)2 ChannelInitializer (io.netty.channel.ChannelInitializer)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 EventLoopGroup (io.netty.channel.EventLoopGroup)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2