public static Http2Settings defaultSettings() { return new Http2Settings().maxHeaderListSize(DEFAULT_HEADER_LIST_SIZE); } }
/** * 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(); } }
@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; }
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; }
private void readSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception { if (flags.ack()) { listener.onSettingsAckRead(ctx); } else { int numSettings = payloadLength / SETTING_ENTRY_LENGTH; Http2Settings settings = new Http2Settings(); for (int index = 0; index < numSettings; ++index) { char id = (char) payload.readUnsignedShort(); long value = payload.readUnsignedInt(); try { settings.put(id, Long.valueOf(value)); } catch (IllegalArgumentException e) { switch(id) { case SETTINGS_MAX_FRAME_SIZE: throw connectionError(PROTOCOL_ERROR, e, e.getMessage()); case SETTINGS_INITIAL_WINDOW_SIZE: throw connectionError(FLOW_CONTROL_ERROR, e, e.getMessage()); default: throw connectionError(PROTOCOL_ERROR, e, e.getMessage()); } } } listener.onSettingsRead(ctx, settings); } }
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); }
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; }
private Http2Settings http2Settings() { final Http2Settings settings = new Http2Settings(); final int initialWindowSize = config.http2InitialStreamWindowSize(); if (initialWindowSize != Http2CodecUtil.DEFAULT_WINDOW_SIZE) { settings.initialWindowSize(initialWindowSize); } final int maxFrameSize = config.http2MaxFrameSize(); if (maxFrameSize != Http2CodecUtil.DEFAULT_MAX_FRAME_SIZE) { settings.maxFrameSize(maxFrameSize); } // Not using the value greater than 2^31-1 because some HTTP/2 client implementations use a signed // 32-bit integer to represent an HTTP/2 SETTINGS parameter value. settings.maxConcurrentStreams(Math.min(config.http2MaxStreamsPerConnection(), Integer.MAX_VALUE)); settings.maxHeaderListSize(config.http2MaxHeaderListSize()); return settings; }
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 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); }
@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 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; }
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; }
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; }
public static Http2Settings defaultSettings() { return new Http2Settings().maxHeaderListSize(DEFAULT_HEADER_LIST_SIZE); } }
public static Http2Settings defaultSettings() { return new Http2Settings().maxHeaderListSize(DEFAULT_HEADER_LIST_SIZE); } }
/** * 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(); } }
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 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 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; }