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(FRAME_SIZE_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); } }
@Test public void settingsFrameShouldMatch() throws Exception { final Http2Settings settings = new Http2Settings(); settings.initialWindowSize(10); settings.maxConcurrentStreams(1000); settings.headerTableSize(4096); runInChannel( clientChannel, new Http2Runnable() { @Override public void run() { frameWriter.writeSettings(ctx(), newPromise(), settings); } }); awaitRequests(); verify(serverObserver).onSettingsRead(any(ChannelHandlerContext.class), eq(settings)); }
private void readSettingsFrame( ChannelHandlerContext ctx, ByteBuf payload, Http2FrameObserver observer) throws Http2Exception { if (flags.ack()) { observer.onSettingsAckRead(ctx); } else { int numSettings = payloadLength / SETTING_ENTRY_LENGTH; Http2Settings settings = new Http2Settings(); for (int index = 0; index < numSettings; ++index) { short id = payload.readUnsignedByte(); long value = payload.readUnsignedInt(); switch (id) { case SETTINGS_HEADER_TABLE_SIZE: if (value < 0 || value > Integer.MAX_VALUE) { throw protocolError("Invalid value for HEADER_TABLE_SIZE: %d", value); } settings.maxHeaderTableSize((int) value); break; case SETTINGS_COMPRESS_DATA: if (value != 0 && value != 1) { throw protocolError("Invalid value for COMPRESS_DATA: %d", value); } settings.allowCompressedData(value == 1); break; case SETTINGS_ENABLE_PUSH: if (value != 0 && value != 1) { throw protocolError("Invalid value for ENABLE_PUSH: %d", value); } settings.pushEnabled(value == 1); break; case SETTINGS_INITIAL_WINDOW_SIZE: if (value < 0 || value > Integer.MAX_VALUE) { throw protocolError("Invalid value for INITIAL_WINDOW_SIZE: %d", value); } settings.initialWindowSize((int) value); break; case SETTINGS_MAX_CONCURRENT_STREAMS: if (value < 0 || value > Integer.MAX_VALUE) { throw protocolError("Invalid value for MAX_CONCURRENT_STREAMS: %d", value); } settings.maxConcurrentStreams((int) value); break; default: throw protocolError("Unsupport setting: %d", id); } } observer.onSettingsRead(ctx, settings); } }