@Test public void testSettings() { Http2Settings settings = new Http2Settings(); assertEquals(true, settings.isPushEnabled()); assertEquals(Http2Settings.DEFAULT_MAX_HEADER_LIST_SIZE, settings.getMaxHeaderListSize()); assertEquals(Http2Settings.DEFAULT_MAX_CONCURRENT_STREAMS, settings.getMaxConcurrentStreams()); assertEquals(Http2Settings.DEFAULT_INITIAL_WINDOW_SIZE, settings.getInitialWindowSize()); assertEquals(Http2Settings.DEFAULT_MAX_FRAME_SIZE, settings.getMaxFrameSize()); assertEquals(null, settings.getExtraSettings()); assertFalse(settings.equals(update)); assertNotSame(settings.hashCode(), settings.hashCode()); assertSame(settings, settings.setHeaderTableSize(update.getHeaderTableSize())); assertEquals(settings.getHeaderTableSize(), update.getHeaderTableSize()); assertSame(settings, settings.setPushEnabled(update.isPushEnabled())); assertEquals(settings.isPushEnabled(), update.isPushEnabled()); assertSame(settings, settings.setMaxHeaderListSize(update.getMaxHeaderListSize())); assertEquals(settings.getMaxHeaderListSize(), update.getMaxHeaderListSize()); assertSame(settings, settings.setMaxConcurrentStreams(update.getMaxConcurrentStreams())); assertEquals(settings.getMaxConcurrentStreams(), update.getMaxConcurrentStreams()); assertSame(settings, settings.setInitialWindowSize(update.getInitialWindowSize())); assertEquals(settings.getInitialWindowSize(), update.getInitialWindowSize()); assertSame(settings, settings.setMaxFrameSize(update.getMaxFrameSize())); assertEquals(settings.getMaxFrameSize(), update.getMaxFrameSize()); assertSame(settings, settings.setExtraSettings(update.getExtraSettings())); Map<Integer, Long> extraSettings = new HashMap<>(update.getExtraSettings()); assertEquals(update.getExtraSettings(), extraSettings); extraSettings.clear(); assertEquals(update.getExtraSettings(), settings.getExtraSettings());
@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); assertEquals(s3, s1); assertEquals(s1.hashCode(), s2.hashCode()); assertEquals(s2.hashCode(), s3.hashCode()); assertFalse(s1.equals(null)); assertFalse(s2.equals(null)); assertFalse(s3.equals(null)); assertNotEquals(s4, s3); assertNotEquals(s1.hashCode(), s4.hashCode()); assertNotEquals(s2.hashCode(), s4.hashCode()); assertNotEquals(s3.hashCode(), s4.hashCode());
static void toJson(Http2Settings obj, java.util.Map<String, Object> json) { json.put("headerTableSize", obj.getHeaderTableSize()); json.put("initialWindowSize", obj.getInitialWindowSize()); json.put("maxConcurrentStreams", obj.getMaxConcurrentStreams()); json.put("maxFrameSize", obj.getMaxFrameSize()); json.put("maxHeaderListSize", obj.getMaxHeaderListSize()); json.put("pushEnabled", obj.isPushEnabled()); } }
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 "headerTableSize": if (member.getValue() instanceof Number) { obj.setHeaderTableSize(((Number)member.getValue()).longValue()); obj.setInitialWindowSize(((Number)member.getValue()).intValue()); obj.setMaxConcurrentStreams(((Number)member.getValue()).longValue()); obj.setMaxFrameSize(((Number)member.getValue()).intValue()); obj.setMaxHeaderListSize(((Number)member.getValue()).longValue()); obj.setPushEnabled((Boolean)member.getValue());
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) { converted.setPushEnabled(pushEnabled); converted.setMaxConcurrentStreams(maxConcurrentStreams); converted.setMaxHeaderListSize(maxHeaderListSize); converted.setMaxFrameSize(maxFrameSize); converted.setInitialWindowSize(initialWindowSize); converted.setHeaderTableSize(headerTableSize); converted.set(key, value);
@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(); }
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;
@Test public void testServerSettings() throws Exception { io.vertx.core.http.Http2Settings expectedSettings = TestUtils.randomHttp2Settings(); expectedSettings.setHeaderTableSize((int)io.vertx.core.http.Http2Settings.DEFAULT_HEADER_TABLE_SIZE); server.close(); server = vertx.createHttpServer(serverOptions); switch (count.getAndIncrement()) { case 0: assertEquals(expectedSettings.getMaxHeaderListSize(), settings.getMaxHeaderListSize()); assertEquals(expectedSettings.getMaxFrameSize(), settings.getMaxFrameSize()); assertEquals(expectedSettings.getInitialWindowSize(), settings.getInitialWindowSize()); assertEquals(expectedSettings.getMaxConcurrentStreams(), settings.getMaxConcurrentStreams()); assertEquals(expectedSettings.getHeaderTableSize(), settings.getHeaderTableSize()); assertEquals(expectedSettings.get('\u0007'), settings.get(7)); testComplete(); break;
io.vertx.core.http.Http2Settings initialSettings = TestUtils.randomHttp2Settings(); io.vertx.core.http.Http2Settings updatedSettings = TestUtils.randomHttp2Settings(); updatedSettings.setHeaderTableSize(initialSettings.getHeaderTableSize()); // Otherwise it raise "invalid max dynamic table size" in Netty AtomicInteger count = new AtomicInteger(); Future<Void> end = Future.future(); }).connectionHandler(conn -> { io.vertx.core.http.Http2Settings initialRemoteSettings = conn.remoteSettings(); assertEquals(initialSettings.isPushEnabled(), initialRemoteSettings.isPushEnabled()); assertEquals(initialSettings.getMaxHeaderListSize(), initialRemoteSettings.getMaxHeaderListSize()); assertEquals(initialSettings.getMaxFrameSize(), initialRemoteSettings.getMaxFrameSize()); assertEquals(initialSettings.getInitialWindowSize(), initialRemoteSettings.getInitialWindowSize()); assertEquals(initialSettings.getHeaderTableSize(), initialRemoteSettings.getHeaderTableSize()); assertEquals(initialSettings.get('\u0007'), initialRemoteSettings.get(7)); Context ctx = Vertx.currentContext(); conn.remoteSettingsHandler(settings -> { assertEquals(updatedSettings.getMaxHeaderListSize(), settings.getMaxHeaderListSize()); assertEquals(updatedSettings.getMaxFrameSize(), settings.getMaxFrameSize()); assertEquals(updatedSettings.getInitialWindowSize(), settings.getInitialWindowSize()); assertEquals(updatedSettings.getHeaderTableSize(), settings.getHeaderTableSize()); assertEquals(updatedSettings.get('\u0007'), settings.get(7)); complete(); break;
@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); }
@Override public String toString() { return toJson().encode(); }
@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)); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; HttpServerOptions that = (HttpServerOptions) o; if (compressionSupported != that.compressionSupported) return false; if (maxWebsocketFrameSize != that.maxWebsocketFrameSize) return false; if (maxWebsocketMessageSize != that.maxWebsocketMessageSize) return false; if (handle100ContinueAutomatically != that.handle100ContinueAutomatically) return false; if (maxChunkSize != that.maxChunkSize) return false; if (maxInitialLineLength != that.maxInitialLineLength) return false; if (maxHeaderSize != that.maxHeaderSize) return false; if (initialSettings == null ? that.initialSettings != null : !initialSettings.equals(that.initialSettings)) return false; if (alpnVersions == null ? that.alpnVersions != null : !alpnVersions.equals(that.alpnVersions)) return false; if (http2ConnectionWindowSize != that.http2ConnectionWindowSize) return false; if (decompressionSupported != that.decompressionSupported) return false; if (acceptUnmaskedFrames != that.acceptUnmaskedFrames) return false; if (decoderInitialBufferSize != that.decoderInitialBufferSize) return false; if (websocketDeflateFrameCompressionSupported != that.websocketDeflateFrameCompressionSupported) return false; if (websocketPermessageDeflateCompressionSupported != that.websocketPermessageDeflateCompressionSupported) return false; if (websocketCompressionLevel != that.websocketCompressionLevel) return false; if (websocketCompressionAllowServerNoContext != that.websocketCompressionAllowServerNoContext) return false; if (websocketCompressionPreferredClientNoContext != that.websocketCompressionPreferredClientNoContext) return false; return !(websocketSubProtocols != null ? !websocketSubProtocols.equals(that.websocketSubProtocols) : that.websocketSubProtocols != null); }
long concurrency = conn.remoteSettings().getMaxConcurrentStreams(); if (http2MaxConcurrency > 0) { concurrency = Math.min(concurrency, http2MaxConcurrency);
public static void fromVertxInitialSettings(boolean server, io.vertx.core.http.Http2Settings vertxSettings, Http2Settings nettySettings) { if (vertxSettings != null) { if (!server && vertxSettings.isPushEnabled() != DEFAULT_ENABLE_PUSH) { nettySettings.pushEnabled(vertxSettings.isPushEnabled()); } if (vertxSettings.getHeaderTableSize() != DEFAULT_HEADER_TABLE_SIZE) { nettySettings.put('\u0001', (Long)vertxSettings.getHeaderTableSize()); } if (vertxSettings.getInitialWindowSize() != DEFAULT_INITIAL_WINDOW_SIZE) { nettySettings.initialWindowSize(vertxSettings.getInitialWindowSize()); } if (vertxSettings.getMaxConcurrentStreams() != DEFAULT_MAX_CONCURRENT_STREAMS) { nettySettings.maxConcurrentStreams(vertxSettings.getMaxConcurrentStreams()); } if (vertxSettings.getMaxFrameSize() != DEFAULT_MAX_FRAME_SIZE) { nettySettings.maxFrameSize(vertxSettings.getMaxFrameSize()); } if (vertxSettings.getMaxHeaderListSize() != DEFAULT_MAX_HEADER_LIST_SIZE) { nettySettings.maxHeaderListSize(vertxSettings.getMaxHeaderListSize()); } Map<Integer, Long> extraSettings = vertxSettings.getExtraSettings(); if (extraSettings != null) { extraSettings.forEach((code, setting) -> { nettySettings.put((char)(int)code, setting); }); } } }
/** * 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; }
switch (id) { case 1: setHeaderTableSize(value); break; case 2: Arguments.require(value == 0 || value == 1, "enablePush must be 0 or 1"); setPushEnabled(value == 1); break; case 3: setMaxConcurrentStreams(value); break; case 4: setInitialWindowSize((int) value); break; case 5: setMaxFrameSize((int) value); break; case 6: Arguments.require(value <= Integer.MAX_VALUE, "maxHeaderListSize must be <= " + Integer.MAX_VALUE); setMaxHeaderListSize((int) value); break; default:
@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(); }
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); client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }).connectionHandler(conn -> { assertEquals(max == null ? 0xFFFFFFFFL : max, conn.remoteSettings().getMaxConcurrentStreams()); latch.countDown(); }).exceptionHandler(err -> {