From bd5659bbe105edb7883853be7209cab663040a01 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 11 Dec 2018 07:44:19 +0100 Subject: [PATCH] MINOR: hpack: provide a function to encode a long indexed header For long header values whose index is known, hpack_encodde_long_idx() may now be used. This function emits the short index and follows with the header's value. --- include/common/hpack-enc.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/common/hpack-enc.h b/include/common/hpack-enc.h index a0fc0f37c5..4e60104bd4 100644 --- a/include/common/hpack-enc.h +++ b/include/common/hpack-enc.h @@ -29,6 +29,7 @@ #define _COMMON_HPACK_ENC_H #include +#include #include #include #include @@ -97,4 +98,29 @@ static inline int hpack_encode_short_idx(struct buffer *out, int idx, struct ist return 1; } +/* Tries to encode header field index with long value into the + * aligned buffer . Returns non-zero on success, 0 on failure (buffer + * full). The caller is responsible for ensuring is lower than 64 (static + * list only), and that the buffer is aligned (head==0). + */ +static inline int hpack_encode_long_idx(struct buffer *out, int idx, struct ist val) +{ + int len = out->data; + + if (!hpack_len_to_bytes(val.len) || + 1 + len + hpack_len_to_bytes(val.len) + val.len > out->size) + return 0; + + /* emit literal with indexing (7541#6.2.1) : + * [ 0 | 1 | Index (6+) ] + */ + out->area[len++] = idx | 0x40; + len = hpack_encode_len(out->area, len, val.len); + memcpy(out->area + len, val.ptr, val.len); + len += val.len; + + out->data = len; + return 1; +} + #endif /* _COMMON_HPACK_ENC_H */ -- 2.47.3