MINOR: mux-h1: Be able to set custom status code on parsing error
When a parsing error is triggered, the status code may be customized by
setting H1C .errcode field. By default a 400-Bad-Request is returned. The
function h1_handle_bad_req() has been renamed to h1_handle_parsing_error()
to be more generic.
diff --git a/src/mux_h1.c b/src/mux_h1.c
index 7d7158f..3a02d11 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -2428,10 +2428,12 @@
return ret;
}
-/* Try to send a 400 bad request error. It relies on h1_send_error to send the
- * error. This function takes care of incrementing stats and tracked counters.
+/* Try to send an error because of a parsing error. By default a 400 bad request
+ * error is returned. But the status code may be specified by setting
+ * h1c->errcode. It relies on h1_send_error to send the error. This function
+ * takes care of incrementing stats and tracked counters.
*/
-static int h1_handle_bad_req(struct h1c *h1c)
+static int h1_handle_parsing_error(struct h1c *h1c)
{
struct session *sess = h1c->conn->owner;
int ret = 1;
@@ -2447,7 +2449,8 @@
if (sess->listener && sess->listener->counters)
_HA_ATOMIC_INC(&sess->listener->counters->failed_req);
- h1c->errcode = 400;
+ if (!h1c->errcode)
+ h1c->errcode = 400;
ret = h1_send_error(h1c);
if (b_data(&h1c->ibuf) || !(sess->fe->options & PR_O_NULLNOLOG))
sess_log(sess);
@@ -2726,7 +2729,7 @@
TRACE_ERROR("internal error detected", H1_EV_H1C_WAKE|H1_EV_H1C_ERR);
}
else if (h1s->flags & H1S_F_PARSING_ERROR) {
- h1_handle_bad_req(h1c);
+ h1_handle_parsing_error(h1c);
h1c->flags = (h1c->flags & ~(H1C_F_ST_IDLE|H1C_F_WAIT_NEXT_REQ)) | H1C_F_ST_ERROR;
TRACE_ERROR("parsing error detected", H1_EV_H1C_WAKE|H1_EV_H1C_ERR);
}
@@ -2743,7 +2746,7 @@
/* No conn-stream or not ready */
/* shutdown for reads and error on the frontend connection: Send an error */
if (!(h1c->flags & (H1C_F_IS_BACK|H1C_F_ST_ERROR))) {
- if (h1_handle_bad_req(h1c))
+ if (h1_handle_parsing_error(h1c))
h1_send(h1c);
h1c->flags = (h1c->flags & ~(H1C_F_ST_IDLE|H1C_F_WAIT_NEXT_REQ)) | H1C_F_ST_ERROR;
}