Exemplo n.º 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);
   }
 }
Exemplo n.º 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));
   }
 }
Exemplo n.º 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);
   }
 }
Exemplo n.º 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);
   }
 }
Exemplo n.º 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);
   }
 }
Exemplo n.º 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));
       }
     }
   }
 }
Exemplo n.º 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));
   }
 }