maxHeaderSize = DEFAULT_MAX_HEADER_SIZE; maxWaitQueueSize = DEFAULT_MAX_WAIT_QUEUE_SIZE; initialSettings = new Http2Settings(); alpnVersions = new ArrayList<>(DEFAULT_ALPN_VERSIONS); http2ClearTextUpgrade = DEFAULT_HTTP2_CLEAR_TEXT_UPGRADE;
private void init() { compressionSupported = DEFAULT_COMPRESSION_SUPPORTED; compressionLevel = DEFAULT_COMPRESSION_LEVEL; maxWebsocketFrameSize = DEFAULT_MAX_WEBSOCKET_FRAME_SIZE; maxWebsocketMessageSize = DEFAULT_MAX_WEBSOCKET_MESSAGE_SIZE; handle100ContinueAutomatically = DEFAULT_HANDLE_100_CONTINE_AUTOMATICALLY; maxChunkSize = DEFAULT_MAX_CHUNK_SIZE; maxInitialLineLength = DEFAULT_MAX_INITIAL_LINE_LENGTH; maxHeaderSize = DEFAULT_MAX_HEADER_SIZE; initialSettings = new Http2Settings().setMaxConcurrentStreams(DEFAULT_INITIAL_SETTINGS_MAX_CONCURRENT_STREAMS); alpnVersions = new ArrayList<>(DEFAULT_ALPN_VERSIONS); http2ConnectionWindowSize = DEFAULT_HTTP2_CONNECTION_WINDOW_SIZE; decompressionSupported = DEFAULT_DECOMPRESSION_SUPPORTED; acceptUnmaskedFrames = DEFAULT_ACCEPT_UNMASKED_FRAMES; decoderInitialBufferSize = DEFAULT_DECODER_INITIAL_BUFFER_SIZE; websocketDeflateFrameCompressionSupported = DEFAULT_WEBSOCKET_SUPPORT_DEFLATE_FRAME_COMPRESSION; websocketPermessageDeflateCompressionSupported = DEFAULT_WEBSOCKET_SUPPORT_PERMESSAGE_DEFLATE_COMPRESSION; websocketCompressionLevel = DEFAULT_WEBSOCKET_COMPRESSION_LEVEL; websocketCompressionPreferredClientNoContext = DEFAULT_WEBSOCKET_COMPRESSION_PREFERRED_CLIENT_NO_CONTEXT; websocketCompressionAllowServerNoContext = DEFAULT_WEBSOCKET_COMPRESSION_ALLOW_SERVER_NO_CONTEXT; }
case "initialSettings": if (member.getValue() instanceof JsonObject) { obj.setInitialSettings(new io.vertx.core.http.Http2Settings((JsonObject)member.getValue()));
case "initialSettings": if (member.getValue() instanceof JsonObject) { obj.setInitialSettings(new io.vertx.core.http.Http2Settings((JsonObject)member.getValue()));
@Test public void testSettinsMax() { for (int i = 1;i <= 6;i++) { try { new Http2Settings().set(i, max[i - 1] + 1); fail("Was expecting setting " + (i - 1) + " update to throw IllegalArgumentException"); } catch (IllegalArgumentException ignore) { } } Http2Settings settings = new Http2Settings(); for (int i = 1;i <= 6;i++) { settings.set(i, max[i - 1]); } HttpUtils.fromVertxSettings(settings); }
@Test public void testSettingsMin() { for (int i = 1;i <= 6;i++) { try { new Http2Settings().set(i, min[i - 1] - 1); fail(); } catch (IllegalArgumentException ignore) { } } Http2Settings settings = new Http2Settings(); for (int i = 1;i <= 6;i++) { settings.set(i, min[i - 1]); } HttpUtils.fromVertxSettings(settings); }
/** * Copy constructor * * @param other the options to copy */ public HttpServerOptions(HttpServerOptions other) { super(other); this.compressionSupported = other.isCompressionSupported(); this.compressionLevel = other.getCompressionLevel(); this.maxWebsocketFrameSize = other.getMaxWebsocketFrameSize(); this.maxWebsocketMessageSize = other.getMaxWebsocketMessageSize(); this.websocketSubProtocols = other.getWebsocketSubProtocols(); this.handle100ContinueAutomatically = other.handle100ContinueAutomatically; this.maxChunkSize = other.getMaxChunkSize(); this.maxInitialLineLength = other.getMaxInitialLineLength(); this.maxHeaderSize = other.getMaxHeaderSize(); this.initialSettings = other.initialSettings != null ? new Http2Settings(other.initialSettings) : null; this.alpnVersions = other.alpnVersions != null ? new ArrayList<>(other.alpnVersions) : null; this.http2ConnectionWindowSize = other.http2ConnectionWindowSize; this.decompressionSupported = other.isDecompressionSupported(); this.acceptUnmaskedFrames = other.isAcceptUnmaskedFrames(); this.decoderInitialBufferSize = other.getDecoderInitialBufferSize(); this.websocketDeflateFrameCompressionSupported = other.websocketDeflateFrameCompressionSupported; this.websocketPermessageDeflateCompressionSupported = other.websocketPermessageDeflateCompressionSupported; this.websocketCompressionLevel = other.websocketCompressionLevel; this.websocketCompressionPreferredClientNoContext = other.websocketCompressionPreferredClientNoContext; this.websocketCompressionAllowServerNoContext = other.websocketCompressionAllowServerNoContext; }
@Test public void testInvalidSettings() throws Exception { io.vertx.core.http.Http2Settings settings = new io.vertx.core.http.Http2Settings(); try { settings.set(Integer.MAX_VALUE, 0); fail("max id should be 0-0xFFFF"); } catch (RuntimeException e) { // expected } try { settings.set(7, -1); fail("max value should be 0-0xFFFFFFFF"); } catch (RuntimeException e) { // expected } }
this.maxHeaderSize = other.getMaxHeaderSize(); this.maxWaitQueueSize = other.maxWaitQueueSize; this.initialSettings = other.initialSettings != null ? new Http2Settings(other.initialSettings) : null; this.alpnVersions = other.alpnVersions != null ? new ArrayList<>(other.alpnVersions) : null; this.http2ClearTextUpgrade = other.http2ClearTextUpgrade;
@Test public void testResetClientRequestNotYetSent() throws Exception { waitFor(2); server.close(); server = vertx.createHttpServer(createBaseServerOptions().setInitialSettings(new Http2Settings().setMaxConcurrentStreams(1))); AtomicInteger numReq = new AtomicInteger(); server.requestHandler(req -> { assertEquals(0, numReq.getAndIncrement()); req.response().end(); complete(); }); startServer(); HttpClientRequest post = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { fail(); }); post.setChunked(true).write(TestUtils.randomBuffer(1024)); assertTrue(post.reset()); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { assertEquals(1, numReq.get()); complete(); }); await(); }
@Test public void testInitialMaxConcurrentStreamZero() throws Exception { server.close(); server = vertx.createHttpServer(createBaseServerOptions().setInitialSettings(new Http2Settings().setMaxConcurrentStreams(0))); server.requestHandler(req -> { req.response().end(); }); server.connectionHandler(conn -> { vertx.setTimer(500, id -> { conn.updateSettings(new Http2Settings().setMaxConcurrentStreams(10)); }); }); startServer(); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { testComplete(); }).connectionHandler(conn -> { assertEquals(10, conn.remoteSettings().getMaxConcurrentStreams()); }).setTimeout(10000).exceptionHandler(this::fail).end(); await(); }
@Test public void toNettySettings() { Http2Settings settings = new Http2Settings(); for (int i = 7;i <= 0xFFFF;i += 1) { // we need to clamp the random value to pass validation settings.set(0xFFFF, Math.min(0xFFFFFFFFL, TestUtils.randomPositiveLong())); } io.netty.handler.codec.http2.Http2Settings conv = HttpUtils.fromVertxSettings(settings); for (int i = 1;i <= 0xFFFF;i += 1) { assertEquals(settings.get(i), conv.get((char)i)); } settings = HttpUtils.toVertxSettings(conv); for (int i = 1;i <= 0xFFFF;i += 1) { assertEquals(settings.get(i), conv.get((char)i)); } }
public static io.vertx.core.http.Http2Settings toVertxSettings(Http2Settings settings) { io.vertx.core.http.Http2Settings converted = new io.vertx.core.http.Http2Settings(); Boolean pushEnabled = settings.pushEnabled(); if (pushEnabled != null) {
@Test public void testResetPendingPushPromise() throws Exception { server.requestHandler(req -> { req.response().push(HttpMethod.GET, "/wibble", ar -> { assertFalse(ar.succeeded()); testComplete(); }); }); startServer(); client.close(); client = vertx.createHttpClient(clientOptions.setInitialSettings(new io.vertx.core.http.Http2Settings().setMaxConcurrentStreams(0L))); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", onFailure(resp -> {})); req.pushHandler(pushedReq -> { pushedReq.reset(Http2Error.CANCEL.code()); }); req.end(); await(); }
String expected = TestUtils.randomAlphaString(100); server.close(); io.vertx.core.http.Http2Settings serverSettings = new io.vertx.core.http.Http2Settings(); if (max != null) { serverSettings.setMaxConcurrentStreams(max);
@Test public void testEqualsHashCode() throws Exception { Http2Settings s1 = new Http2Settings().setHeaderTableSize(1024); Http2Settings s2 = new Http2Settings().setHeaderTableSize(1024); Http2Settings s3 = new Http2Settings(s1.toJson()); Http2Settings s4 = new Http2Settings().setHeaderTableSize(2048);
/** * Create random {@link Http2Settings} with valid values. * * @return the random settings */ public static Http2Settings randomHttp2Settings() { long headerTableSize = 10 + randomPositiveInt() % (Http2CodecUtil.MAX_HEADER_TABLE_SIZE - 10); boolean enablePush = randomBoolean(); long maxConcurrentStreams = 10 + randomPositiveLong() % (Http2CodecUtil.MAX_CONCURRENT_STREAMS - 10); int initialWindowSize = 10 + randomPositiveInt() % (Http2CodecUtil.MAX_INITIAL_WINDOW_SIZE - 10); int maxFrameSize = Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND + randomPositiveInt() % (Http2CodecUtil.MAX_FRAME_SIZE_UPPER_BOUND - Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND); long maxHeaderListSize = 10 + randomPositiveLong() % (Http2CodecUtil.MAX_HEADER_LIST_SIZE - 10); Http2Settings settings = new Http2Settings(); settings.setHeaderTableSize(headerTableSize); settings.setPushEnabled(enablePush); settings.setMaxConcurrentStreams(maxConcurrentStreams); settings.setInitialWindowSize(initialWindowSize); settings.setMaxFrameSize(maxFrameSize); settings.setMaxHeaderListSize(maxHeaderListSize); settings.set('\u0007', (randomPositiveLong() & 0xFFFFFFFFL)); return settings; }
@Test public void testSettings() { Http2Settings settings = new Http2Settings(); assertEquals(settings.hashCode(), settings.hashCode()); settings = new Http2Settings(update); assertEquals(settings.getHeaderTableSize(), update.getHeaderTableSize()); assertEquals(settings.isPushEnabled(), update.isPushEnabled());
assertEquals(new Http2Settings().setMaxConcurrentStreams(HttpServerOptions.DEFAULT_INITIAL_SETTINGS_MAX_CONCURRENT_STREAMS), options.getInitialSettings()); assertEquals(options, options.setInitialSettings(initialSettings)); assertEquals(initialSettings, options.getInitialSettings());
assertEquals(new Http2Settings(), options.getInitialSettings()); assertEquals(options, options.setInitialSettings(initialSettings)); assertEquals(initialSettings, options.getInitialSettings());