case "http2ClearTextUpgrade": if (member.getValue() instanceof Boolean) { obj.setHttp2ClearTextUpgrade((Boolean)member.getValue());
@Parameterized.Parameters public static Collection<Object[]> params() { ArrayList<Object[]> params = new ArrayList<>(); // h2 params.add(new Object[] { Http2TestBase.createHttp2ClientOptions(), Http2TestBase.createHttp2ServerOptions(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST) }); // h2c with upgrade params.add(new Object[] { new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setHttp2ClearTextUpgrade(true), new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST) }); // h2c direct params.add(new Object[] { new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setHttp2ClearTextUpgrade(false), new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST) }); return params; }
@Test public void testIdleTimeoutClearTextDirect() throws Exception { testIdleTimeout(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTPS_HOST), clientOptions.setDefaultPort(DEFAULT_HTTP_PORT).setUseAlpn(false).setSsl(false).setHttp2ClearTextUpgrade(false)); }
@Test public void testIdleTimeoutClearTextUpgrade() throws Exception { testIdleTimeout(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTPS_HOST), clientOptions.setDefaultPort(DEFAULT_HTTP_PORT).setUseAlpn(false).setSsl(false).setHttp2ClearTextUpgrade(true)); }
private void testClearText(boolean upgrade) throws Exception { ServerBootstrap bootstrap = createH2CServer((dec, enc) -> new Http2EventAdapter() { @Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception { enc.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), 0, true, ctx.newPromise()); ctx.flush(); } }, upgrade); ChannelFuture s = bootstrap.bind(DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT).sync(); try { client.close(); client = vertx.createHttpClient(clientOptions.setUseAlpn(false).setSsl(false).setHttp2ClearTextUpgrade(upgrade)); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(resp1 -> { HttpConnection conn = resp1.request().connection(); assertEquals(HttpVersion.HTTP_2, resp1.version()); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(resp2 -> { assertSame(((HttpClientConnection)conn).channel(), ((HttpClientConnection)resp2.request().connection()).channel()); testComplete(); })).exceptionHandler(this::fail).end(); })).exceptionHandler(this::fail).end(); await(); } finally { s.channel().close().sync(); } }
@Test public void testClientWebsocketWithHttp2Client() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setHttp2ClearTextUpgrade(false).setProtocolVersion(HttpVersion.HTTP_2)); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)); server.requestHandler(req -> { req.response().setChunked(true).write("connect"); }); server.websocketHandler(ws -> { ws.writeFinalTextFrame("ok"); }); server.listen(onSuccess(server -> { client.getNow(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", resp -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.handler(buff -> { assertEquals("ok", buff.toString()); testComplete(); }); }); }); })); await(); }
options.setSslEngineOptions(sslEngine); options.setAlpnVersions(alpnVersions); options.setHttp2ClearTextUpgrade(h2cUpgrade); options.setLocalAddress(localAddress); options.setSendUnmaskedFrames(sendUnmaskedFrame);
case "http2ClearTextUpgrade": if (member.getValue() instanceof Boolean) { obj.setHttp2ClearTextUpgrade((Boolean)member.getValue());
@Override public HttpClientOptions createHttpClientOptions() { HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion(); HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setProtocolVersion(ver); httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout()); httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleWatchTimeout()); if (ver == HttpVersion.HTTP_2) { LOGGER.debug("service center ws client protocol version is HTTP/2"); httpClientOptions.setHttp2ClearTextUpgrade(false); } if (ServiceRegistryConfig.INSTANCE.isSsl()) { LOGGER.debug("service center ws client performs requests over TLS"); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); } return httpClientOptions; } }
@Parameterized.Parameters public static Collection<Object[]> params() { ArrayList<Object[]> params = new ArrayList<>(); // h2 params.add(new Object[] { Http2TestBase.createHttp2ClientOptions(), Http2TestBase.createHttp2ServerOptions(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST) }); // h2c with upgrade params.add(new Object[] { new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setHttp2ClearTextUpgrade(true), new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST) }); // h2c direct params.add(new Object[] { new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setHttp2ClearTextUpgrade(false), new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST) }); return params; }
private static HttpClientOptions createHttp2ClientOptions() { HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setUseAlpn(TransportClientConfig.getUseAlpn()) .setHttp2ClearTextUpgrade(false) .setProtocolVersion(HttpVersion.HTTP_2) .setIdleTimeout(TransportClientConfig.getHttp2ConnectionIdleTimeoutInSeconds()) .setHttp2MultiplexingLimit(TransportClientConfig.getHttp2MultiplexingLimit()) .setHttp2MaxPoolSize(TransportClientConfig.getHttp2ConnectionMaxPoolSize()) .setTryUseCompression(TransportClientConfig.getConnectionCompression()); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); return httpClientOptions; }
@Override public HttpClientOptions createHttpClientOptions() { HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion(); HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setProtocolVersion(ver); httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout()); httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleConnectionTimeout()); if (ServiceRegistryConfig.INSTANCE.isProxyEnable()) { ProxyOptions proxy = new ProxyOptions(); proxy.setHost(ServiceRegistryConfig.INSTANCE.getProxyHost()); proxy.setPort(ServiceRegistryConfig.INSTANCE.getProxyPort()); proxy.setUsername(ServiceRegistryConfig.INSTANCE.getProxyUsername()); proxy.setPassword(Encryptions.decode(ServiceRegistryConfig.INSTANCE.getProxyPasswd(), PROXY_KEY)); httpClientOptions.setProxyOptions(proxy); } if (ver == HttpVersion.HTTP_2) { LOGGER.debug("service center client protocol version is HTTP/2"); httpClientOptions.setHttp2ClearTextUpgrade(false); } if (ServiceRegistryConfig.INSTANCE.isSsl()) { LOGGER.debug("service center client performs requests over TLS"); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); } return httpClientOptions; } }
@Test public void testIdleTimeoutClearTextUpgrade() throws Exception { testIdleTimeout(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTPS_HOST), clientOptions.setDefaultPort(DEFAULT_HTTP_PORT).setUseAlpn(false).setSsl(false).setHttp2ClearTextUpgrade(true)); }
@Test public void testIdleTimeoutClearTextDirect() throws Exception { testIdleTimeout(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTPS_HOST), clientOptions.setDefaultPort(DEFAULT_HTTP_PORT).setUseAlpn(false).setSsl(false).setHttp2ClearTextUpgrade(false)); }
private void testClearText(boolean upgrade) throws Exception { ServerBootstrap bootstrap = createH2CServer((dec, enc) -> new Http2EventAdapter() { @Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception { enc.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), 0, true, ctx.newPromise()); ctx.flush(); } }, upgrade); ChannelFuture s = bootstrap.bind(DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT).sync(); try { client.close(); client = vertx.createHttpClient(clientOptions.setUseAlpn(false).setSsl(false).setHttp2ClearTextUpgrade(upgrade)); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp1 -> { HttpConnection conn = resp1.request().connection(); assertEquals(HttpVersion.HTTP_2, resp1.version()); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp2 -> { assertSame(((HttpClientConnection)conn).channel(), ((HttpClientConnection)resp2.request().connection()).channel()); testComplete(); }).exceptionHandler(this::fail).end(); }).exceptionHandler(this::fail).end(); await(); } finally { s.channel().close().sync(); } }
@Test public void testClientWebsocketWithHttp2Client() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setHttp2ClearTextUpgrade(false).setProtocolVersion(HttpVersion.HTTP_2)); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)); server.requestHandler(req -> { req.response().setChunked(true).write("connect"); }); server.websocketHandler(ws -> { ws.writeFinalTextFrame("ok"); }); server.listen(onSuccess(server -> { client.getNow(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", resp -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.handler(buff -> { assertEquals("ok", buff.toString()); testComplete(); }); }); }); })); await(); }
assertEquals(options, options.setHttp2ClearTextUpgrade(false)); assertEquals(false, options.isHttp2ClearTextUpgrade());
options.setSslEngineOptions(sslEngine); options.setAlpnVersions(alpnVersions); options.setHttp2ClearTextUpgrade(h2cUpgrade); options.setLocalAddress(localAddress); options.setSendUnmaskedFrames(sendUnmaskedFrame);
private static HttpClientOptions createHttp2ClientOptions() { HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setUseAlpn(TransportClientConfig.getUseAlpn()) .setHttp2ClearTextUpgrade(false) .setProtocolVersion(HttpVersion.HTTP_2) .setIdleTimeout(TransportClientConfig.getHttp2ConnectionIdleTimeoutInSeconds()) .setHttp2MultiplexingLimit(TransportClientConfig.getHttp2MultiplexingLimit()) .setHttp2MaxPoolSize(TransportClientConfig.getHttp2ConnectionMaxPoolSize()) .setTryUseCompression(TransportClientConfig.getConnectionCompression()); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); return httpClientOptions; }
assertEquals(options, options.setHttp2ClearTextUpgrade(false)); assertEquals(false, options.isHttp2ClearTextUpgrade());