]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: qpack: support non-indexed http status code encoding
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 30 Sep 2021 12:47:55 +0000 (14:47 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 8 Oct 2021 13:30:18 +0000 (15:30 +0200)
If a HTTP status code is not present in the QPACK static table, encode
it with a literal field line with name reference.

src/qpack-enc.c

index 4d08836e0dad42c136278579434f44bf17e8e9d7..a5092296dff34ecb90f19a6f4ea86d390618028f 100644 (file)
@@ -73,17 +73,47 @@ int qpack_encode_int_status(struct buffer *out, unsigned int status)
        case 425: idx = 70; break;
        case 500: idx = 71; break;
 
-       default:
-               BUG_ON(1);
-               break;
+       /* status code not in QPACK static table, idx is null. */
+       default: break;
        }
 
-       status_size = qpack_get_prefix_int_size(idx, 6);
-       if (b_room(out) < status_size)
-               return 1;
+       if (idx) {
+               /* status code present in QPACK static table
+                * -> indexed field line
+                */
+               status_size = qpack_get_prefix_int_size(idx, 6);
+               if (b_room(out) < status_size)
+                       return 1;
+
+               qpack_encode_prefix_integer(out, idx, 6, 0xc0);
+       }
+       else {
+               /* status code not present in QPACK static table
+                * -> literal field line with name reference
+                */
+               char a, b, c;
+               a = '0' + status / 100;
+               status -= (status / 100 * 100);
+               b = '0' + status / 10;
+               status -= (status / 10 * 10);
+               c = '0' + status;
+
+               /* field name */
+               if (qpack_encode_prefix_integer(out, 24, 4, 0x50))
+                       return 1;
+
+               /* field value length */
+               if (qpack_encode_prefix_integer(out, 3, 7, 0x00))
+                       return 1;
+
+               if (b_room(out) < 3)
+                       return 1;
+
+               b_putchr(out, a);
+               b_putchr(out, b);
+               b_putchr(out, c);
+       }
 
-       //b_quic_enc_int(out, idx);
-       qpack_encode_prefix_integer(out, idx, 6, 0xc0);
        return 0;
 }