From: Willy Tarreau Date: Thu, 26 Jan 2023 08:38:53 +0000 (+0100) Subject: MINOR: h2: add h2_phdr_to_ist() to make ISTs from pseudo headers X-Git-Tag: v2.8-dev3~82 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=271c440392242b5129ffc68787b781b1c39b4618;p=thirdparty%2Fhaproxy.git MINOR: h2: add h2_phdr_to_ist() to make ISTs from pseudo headers Till now pseudo headers were passed as const strings, but having them as ISTs will be more convenient for traces. This doesn't change anything for strings which are derived from them (and being constants they're still zero-terminated). --- diff --git a/include/haproxy/h2.h b/include/haproxy/h2.h index 8d2aa95117..84e4c76fc2 100644 --- a/include/haproxy/h2.h +++ b/include/haproxy/h2.h @@ -318,21 +318,29 @@ static inline int h2_str_to_phdr(const struct ist str) return 0; } -/* returns the pseudo-header name as a string, or ":UNKNOWN" if unknown */ -static inline const char *h2_phdr_to_str(int phdr) +/* returns the pseudo-header name as an ist, or ":UNKNOWN" if unknown. + * Note that all strings are zero-terminated constants. + */ +static inline struct ist h2_phdr_to_ist(int phdr) { switch (phdr) { - case H2_PHDR_IDX_NONE: return ":NONE"; - case H2_PHDR_IDX_AUTH: return ":authority"; - case H2_PHDR_IDX_METH: return ":method"; - case H2_PHDR_IDX_PATH: return ":path"; - case H2_PHDR_IDX_SCHM: return ":scheme"; - case H2_PHDR_IDX_STAT: return ":status"; - case H2_PHDR_IDX_HOST: return "Host"; - default: return ":UNKNOWN"; + case H2_PHDR_IDX_NONE: return ist(":NONE"); + case H2_PHDR_IDX_AUTH: return ist(":authority"); + case H2_PHDR_IDX_METH: return ist(":method"); + case H2_PHDR_IDX_PATH: return ist(":path"); + case H2_PHDR_IDX_SCHM: return ist(":scheme"); + case H2_PHDR_IDX_STAT: return ist(":status"); + case H2_PHDR_IDX_HOST: return ist("Host"); + default: return ist(":UNKNOWN"); } } +/* returns the pseudo-header name as a string, or ":UNKNOWN" if unknown */ +static inline const char *h2_phdr_to_str(int phdr) +{ + return h2_phdr_to_ist(phdr).ptr; +} + #endif /* _HAPROXY_H2_H */ /*