From 271c440392242b5129ffc68787b781b1c39b4618 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 26 Jan 2023 09:38:53 +0100 Subject: [PATCH] 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). --- include/haproxy/h2.h | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/include/haproxy/h2.h b/include/haproxy/h2.h index 8d2aa95..84e4c76 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 */ /* -- 1.7.10.4