From c22d5dfeb87057e54bb28069a0f79565261802cb Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 24 Nov 2019 14:56:03 +0100 Subject: [PATCH] MINOR: h2: add a function to report H2 error codes as strings Just like we have frame type to string, let's have error to string to improve debugging and traces. --- include/common/h2.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/common/h2.h b/include/common/h2.h index 1e0cf5ee8..03582992a 100644 --- a/include/common/h2.h +++ b/include/common/h2.h @@ -233,6 +233,28 @@ static inline const char *h2_ft_str(int type) } } +/* returns the error code as a string */ +static inline const char *h2_err_str(enum h2_err err) +{ + switch (err) { + case H2_ERR_NO_ERROR : return "NO_ERROR"; + case H2_ERR_PROTOCOL_ERROR : return "PROTOCOL_ERROR"; + case H2_ERR_INTERNAL_ERROR : return "INTERNAL_ERROR"; + case H2_ERR_FLOW_CONTROL_ERROR : return "FLOW_CONTROL_ERROR"; + case H2_ERR_SETTINGS_TIMEOUT : return "SETTINGS_TIMEOUT"; + case H2_ERR_STREAM_CLOSED : return "STREAM_CLOSED"; + case H2_ERR_FRAME_SIZE_ERROR : return "FRAME_SIZE_ERROR"; + case H2_ERR_REFUSED_STREAM : return "REFUSED_STREAM"; + case H2_ERR_CANCEL : return "CANCEL"; + case H2_ERR_COMPRESSION_ERROR : return "COMPRESSION_ERROR"; + case H2_ERR_CONNECT_ERROR : return "CONNECT_ERROR"; + case H2_ERR_ENHANCE_YOUR_CALM : return "ENHANCE_YOUR_CALM"; + case H2_ERR_INADEQUATE_SECURITY : return "INADEQUATE_SECURITY"; + case H2_ERR_HTTP_1_1_REQUIRED : return "HTTP_1_1_REQUIRED"; + default : return "_UNKNOWN_"; + } +} + /* Returns an error code if the frame is valid protocol-wise, otherwise 0. * is the frame type (H2_FT_*), is the direction (1=req, 2=res), is * the stream ID from the frame header, is the frame length from the