示例#1
0
 private void writeString(final ByteBuf buf, final AsciiString s) {
   final int encodedLength = Huffman.encodedLength(s);
   if (encodedLength < s.length()) {
     Hpack.writeHuffmanString(buf, s, encodedLength);
   } else {
     Hpack.writeRawString(buf, s);
   }
 }
示例#2
0
 @Test
 public void testHeaderTableSizeUpdate() throws Exception {
   for (int i = 0; i < 32; i++) {
     int size = 1 << i;
     ByteBuf buf = Unpooled.buffer();
     Hpack.writeDynamicTableSizeUpdate(buf, size);
     int updateSize = Hpack.dynamicTableSizeUpdateSize(size);
     assertThat(buf.readableBytes(), is(updateSize));
   }
 }
示例#3
0
 private void writePath(final ByteBuf buf, final AsciiString path) {
   if (path.equals(PATH_SLASH)) {
     Hpack.writeIndexedHeaderField(buf, 4);
   } else if (path.equals(PATH_INDEX_HTML)) {
     Hpack.writeIndexedHeaderField(buf, 5);
   } else {
     writeLiteralHeaderFieldIncrementalIndexingIndexedName(buf, 4);
     writeString(buf, path);
   }
 }
示例#4
0
 private void writeScheme(final ByteBuf buf, final AsciiString scheme) {
   if (scheme.equals(SCHEME_HTTP)) {
     Hpack.writeIndexedHeaderField(buf, 6);
   } else if (scheme.equals(SCHEME_HTTPS)) {
     Hpack.writeIndexedHeaderField(buf, 7);
   } else {
     writeLiteralHeaderFieldIncrementalIndexingIndexedName(buf, 2);
     writeString(buf, scheme);
   }
 }
示例#5
0
 private void writeMethod(final ByteBuf buf, final AsciiString method) {
   if (method.equals(HttpMethod.GET.asciiName())) {
     Hpack.writeIndexedHeaderField(buf, 2);
   } else if (method.equals(HttpMethod.POST.asciiName())) {
     Hpack.writeIndexedHeaderField(buf, 3);
   } else {
     writeLiteralHeaderFieldIncrementalIndexingIndexedName(buf, 2);
     writeString(buf, method);
   }
 }
示例#6
0
 @Test
 public void testIntegerSize() throws Exception {
   for (int n = 1; n <= 8; n++) {
     for (int i = 0; i < 32; i++) {
       for (int j = 0; j <= i; j++) {
         int value = Math.toIntExact((1L << j) - 1);
         ByteBuf buf = Unpooled.buffer();
         Hpack.writeInteger(buf, 0, n, value);
         int calculatedSize = Hpack.integerSize(n, value);
         final int actualSize = buf.readableBytes();
         assertThat(actualSize, is(calculatedSize));
       }
     }
   }
 }
示例#7
0
 @Theory
 public void testWriteReadInteger(
     @TestedOn(ints = {1, 2, 3, 4, 5, 6, 7, 8}) int n,
     @TestedOn(ints = {0, 1, 17, 4711, 80087, 22193521}) int i)
     throws Exception {
   final int maxMaskBits = 8 - n;
   for (int maskBits = 0; maskBits < maxMaskBits; maskBits++) {
     final int mask = 0xFF << (8 - maskBits);
     final ByteBuf buf = Unpooled.buffer();
     writeInteger(buf, mask, n, i);
     assertThat(Hpack.readInteger(buf, n), is(i));
   }
 }