diff --git a/include/common/hpack-enc.h b/include/common/hpack-enc.h index e680346015..a650cdbb22 100644 --- a/include/common/hpack-enc.h +++ b/include/common/hpack-enc.h @@ -32,6 +32,7 @@ #include #include #include +#include #include int hpack_encode_header(struct buffer *out, const struct ist n, @@ -199,4 +200,24 @@ static inline int hpack_encode_str_status(struct buffer *out, unsigned int statu return hpack_encode_short_idx(out, 8, str); // name=":status" (idx 8) } +/* Tries to encode a :method pseudo-header with the method in , which + * also exists as a string in , into the aligned buffer . Returns + * non-zero on success or 0 on failure (buffer full). The caller is responsible + * for ensuring that the string matches , that it's smaller than 127 + * bytes, and that the buffer is aligned. If is unknown then using + * HTTP_METH_OTHER will lead to the string being encoded as a literal. It's + * inlined because it's easily optimizable. + */ +static inline int hpack_encode_method(struct buffer *out, enum http_meth_t meth, struct ist str) +{ + if (out->data < out->size && meth == HTTP_METH_GET) + out->area[out->data++] = 0x82; // indexed field : idx[02]=(":method", "GET") + else if (out->data < out->size && meth == HTTP_METH_POST) + out->area[out->data++] = 0x83; // indexed field : idx[03]=(":method", "POST") + else + return hpack_encode_short_idx(out, 2, str); // name=":method" (idx 2) + return 1; +} + + #endif /* _COMMON_HPACK_ENC_H */