Refine search
@Override public Http2Settings localSettings() { Http2Settings settings = new Http2Settings(); Http2FrameReader.Configuration config = frameReader.configuration(); Http2HeadersDecoder.Configuration headersConfig = config.headersConfiguration(); Http2FrameSizePolicy frameSizePolicy = config.frameSizePolicy(); settings.initialWindowSize(flowController().initialWindowSize()); settings.maxConcurrentStreams(connection.remote().maxActiveStreams()); settings.headerTableSize(headersConfig.maxHeaderTableSize()); settings.maxFrameSize(frameSizePolicy.maxFrameSize()); settings.maxHeaderListSize(headersConfig.maxHeaderListSize()); if (!connection.isServer()) { // Only set the pushEnabled flag if this is a client endpoint. settings.pushEnabled(connection.local().allowPushTo()); } return settings; }
@Override protected void addHandlersToPipeline(final SSLSession sslSession, final ChannelPipeline pipeline) { pipeline.addLast(new BenchmarkApnsServerHandler.BenchmarkApnsServerHandlerBuilder() .initialSettings(Http2Settings.defaultSettings().maxConcurrentStreams(this.maxConcurrentStreams)) .build()); } }
/** * Gets the {@code SETTINGS_HEADER_TABLE_SIZE} value. If unavailable, returns {@code null}. */ public Long headerTableSize() { return get(SETTINGS_HEADER_TABLE_SIZE); }
public static Http2Settings defaultSettings() { return new Http2Settings().maxHeaderListSize(DEFAULT_HEADER_LIST_SIZE); } }
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; }
private Http2Settings http2Settings() { final Http2Settings settings = new Http2Settings(); final int initialWindowSize = clientFactory.http2InitialStreamWindowSize(); if (initialWindowSize != DEFAULT_WINDOW_SIZE) { settings.initialWindowSize(initialWindowSize); } final int maxFrameSize = clientFactory.http2MaxFrameSize(); if (maxFrameSize != DEFAULT_MAX_FRAME_SIZE) { settings.maxFrameSize(maxFrameSize); } settings.maxHeaderListSize(clientFactory.http2MaxHeaderListSize()); return settings; }
Http2FrameCodec(Http2ConnectionEncoder encoder, Http2ConnectionDecoder decoder, Http2Settings initialSettings) { super(decoder, encoder, initialSettings); decoder.frameListener(new FrameListener()); connection().addListener(new ConnectionListener()); connection().remote().flowController().listener(new Http2RemoteFlowControllerListener()); streamKey = connection().newKey(); upgradeKey = connection().newKey(); initialFlowControlWindowSize = initialSettings.initialWindowSize(); }
private void configureHttp2(ChannelPipeline pipeline) { // setup the initial stream settings for the server to use. Http2Settings settings = new Http2Settings() .maxConcurrentStreams(maxConcurrentStreams) .initialWindowSize(initialWindowSize) .headerTableSize(maxHeaderTableSize) .maxHeaderListSize(maxHeaderListSize); Http2MultiplexCodec multiplexCodec = Http2MultiplexCodecBuilder .forServer(http2StreamHandler) .frameLogger(FRAME_LOGGER) .initialSettings(settings) .validateHeaders(true) .build(); pipeline.replace("codec_placeholder", HTTP_CODEC_HANDLER_NAME, multiplexCodec); // Need to pass the connection to our handler later, so store it on channel now. Http2Connection connection = multiplexCodec.connection(); pipeline.channel().attr(H2_CONN_KEY).set(connection); }
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); Long maxConcurrentStreams = settings.maxConcurrentStreams(); if (maxConcurrentStreams != null) { converted.setMaxConcurrentStreams(maxConcurrentStreams); Long maxHeaderListSize = settings.maxHeaderListSize(); if (maxHeaderListSize != null) { converted.setMaxHeaderListSize(maxHeaderListSize); Integer maxFrameSize = settings.maxFrameSize(); if (maxFrameSize != null) { converted.setMaxFrameSize(maxFrameSize); Integer initialWindowSize = settings.initialWindowSize(); if (initialWindowSize != null) { converted.setInitialWindowSize(initialWindowSize); Long headerTableSize = settings.headerTableSize(); if (headerTableSize != null) { converted.setHeaderTableSize(headerTableSize); settings.forEach((key, value) -> { if (key > 6) { converted.set(key, value);
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); }); } } }
public static Http2Handler newHandler(final boolean isServer) { Http2HeadersDecoder headersDecoder = new DefaultHttp2HeadersDecoder(true); Http2FrameReader frameReader = new DefaultHttp2FrameReader(headersDecoder); Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter(); Http2Connection connection = new DefaultHttp2Connection(isServer); Http2ConnectionEncoder encoder = new StreamBufferingEncoder( new DefaultHttp2ConnectionEncoder(connection, frameWriter)); connection.local().flowController(new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true)); Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader); Http2Settings settings = new Http2Settings(); if (!isServer) settings.pushEnabled(true); settings.initialWindowSize(1048576 * 10); //10MiB settings.maxConcurrentStreams(Integer.MAX_VALUE); return newHandler(decoder, encoder, settings, isServer); }
private T buildFromConnection(Http2Connection connection) { Long maxHeaderListSize = initialSettings.maxHeaderListSize(); Http2FrameReader reader = new DefaultHttp2FrameReader(new DefaultHttp2HeadersDecoder(isValidateHeaders(), maxHeaderListSize == null ? DEFAULT_HEADER_LIST_SIZE : maxHeaderListSize, initialHuffmanDecodeCapacity)); Http2FrameWriter writer = encoderIgnoreMaxHeaderListSize == null ? new DefaultHttp2FrameWriter(headerSensitivityDetector()) : new DefaultHttp2FrameWriter(headerSensitivityDetector(), encoderIgnoreMaxHeaderListSize); if (frameLogger != null) { reader = new Http2InboundFrameLogger(reader, frameLogger); writer = new Http2OutboundFrameLogger(writer, frameLogger); } Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, writer); boolean encoderEnforceMaxConcurrentStreams = encoderEnforceMaxConcurrentStreams(); if (encoderEnforceMaxConcurrentStreams) { if (connection.isServer()) { encoder.close(); reader.close(); throw new IllegalArgumentException( "encoderEnforceMaxConcurrentStreams: " + encoderEnforceMaxConcurrentStreams + " not supported for server"); } encoder = new StreamBufferingEncoder(encoder); } Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, reader); return buildFromCodec(decoder, encoder); }
static Http2Settings decodeSettings(String base64Settings) { try { Http2Settings settings = new Http2Settings(); Buffer buffer = Buffer.buffer(Base64.getUrlDecoder().decode(base64Settings)); int pos = 0; int len = buffer.length(); while (pos < len) { int i = buffer.getUnsignedShort(pos); pos += 2; long j = buffer.getUnsignedInt(pos); pos += 4; settings.put((char)i, (Long)j); } return settings; } catch (Exception ignore) { } return null; }
@Override public ChannelFuture writeSettings(ChannelHandlerContext ctx, Http2Settings settings, ChannelPromise promise) { outstandingLocalSettingsQueue.add(settings); try { Boolean pushEnabled = settings.pushEnabled(); if (pushEnabled != null && connection.isServer()) { throw connectionError(PROTOCOL_ERROR, "Server sending SETTINGS frame with ENABLE_PUSH specified"); } } catch (Throwable e) { return promise.setFailure(e); } return frameWriter.writeSettings(ctx, settings, promise); }
@Override protected NettyHttp2Handler build(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings) throws Exception { NettyHttp2Handler handler = new NettyHttp2Handler(decoder, encoder, initialSettings, heartbeatTimeoutThreshold); frameListener(handler); initialSettings().pushEnabled(true); initialSettings().initialWindowSize(1073741824); initialSettings().maxFrameSize(1024 * 1024); return handler; }
@Override public synchronized void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) { Long v = settings.maxConcurrentStreams(); if (v != null) { maxConcurrentStreams = v; } super.onSettingsRead(ctx, settings); }
private Http2ConnectionHandler newHttp2ConnectionHandler(ChannelPipeline pipeline) { final Http2Connection conn = new DefaultHttp2Connection(true); conn.addListener(new Http2GoAwayListener(pipeline.channel())); try (Http2FrameReader reader = new DefaultHttp2FrameReader(true)) { Http2FrameWriter writer = new DefaultHttp2FrameWriter(); Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer); Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader); final Http2ConnectionHandler handler = new Http2ServerConnectionHandler(decoder, encoder, new Http2Settings()); // Setup post build options final Http2RequestDecoder listener = new Http2RequestDecoder(config, pipeline.channel(), handler.encoder()); handler.connection().addListener(listener); handler.decoder().frameListener(listener); handler.gracefulShutdownTimeoutMillis(config.idleTimeoutMillis()); return handler; } }
@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; }
private Http2Settings initialSettings = Http2Settings.defaultSettings(); private Http2FrameListener frameListener; private long gracefulShutdownTimeoutMillis = Http2CodecUtil.DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_MILLIS;
/** * Decodes the settings frame and returns the settings. */ private Http2Settings decodeSettings(ChannelHandlerContext ctx, ByteBuf frame) throws Http2Exception { try { final Http2Settings decodedSettings = new Http2Settings(); frameReader.readFrame(ctx, frame, new Http2FrameAdapter() { @Override public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) { decodedSettings.copyFrom(settings); } }); return decodedSettings; } finally { frame.release(); } }