Пример #1
0
 @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));
 }
Пример #2
0
 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);
   }
 }