diff --git a/include/common/hpack-enc.h b/include/common/hpack-enc.h index a0fc0f37c..4e60104bd 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 */