From: Christopher Faulet Date: Wed, 17 Jul 2019 20:02:08 +0000 (+0200) Subject: MINOR: http: Don't store raw HTTP errors in chunks anymore X-Git-Tag: v2.1-dev2~336 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f734638976bde45e96a833a6da32adea2d3a1d15;p=thirdparty%2Fhaproxy.git MINOR: http: Don't store raw HTTP errors in chunks anymore Default HTTP error messages are stored in an array of chunks. And since the HTX was added, these messages are also converted in HTX and stored in another array. But now, the first array is not used anymore because the legacy HTTP mode was removed. So now, only the array with the HTX messages are kept. The other one was removed. --- diff --git a/include/common/http.h b/include/common/http.h index b0befa5f1c..537be5a01a 100644 --- a/include/common/http.h +++ b/include/common/http.h @@ -120,7 +120,6 @@ struct http_method_desc { extern const int http_err_codes[HTTP_ERR_SIZE]; extern const char *http_err_msgs[HTTP_ERR_SIZE]; -extern struct buffer http_err_chunks[HTTP_ERR_SIZE]; extern const struct ist http_known_methods[HTTP_METH_OTHER]; extern const uint8_t http_char_classes[256]; @@ -134,7 +133,6 @@ extern const char *HTTP_308; extern const char *HTTP_401_fmt; extern const char *HTTP_407_fmt; -int init_http(char **err); enum http_meth_t find_http_meth(const char *str, const int len); int http_get_status_idx(unsigned int status); const char *http_get_reason(unsigned int status); diff --git a/include/proto/http_htx.h b/include/proto/http_htx.h index a134052234..e33fdbec6f 100644 --- a/include/proto/http_htx.h +++ b/include/proto/http_htx.h @@ -28,7 +28,7 @@ #include -extern struct buffer htx_err_chunks[HTTP_ERR_SIZE]; +extern struct buffer http_err_chunks[HTTP_ERR_SIZE]; struct htx_sl *http_get_stline(struct htx *htx); int http_find_header(const struct htx *htx, const struct ist name, struct http_hdr_ctx *ctx, int full); @@ -47,5 +47,6 @@ unsigned int http_get_htx_hdr(const struct htx *htx, const struct ist hdr, int occ, struct http_hdr_ctx *ctx, char **vptr, size_t *vlen); unsigned int http_get_htx_fhdr(const struct htx *htx, const struct ist hdr, int occ, struct http_hdr_ctx *ctx, char **vptr, size_t *vlen); +struct htx *http_str_to_htx(struct buffer *buf, struct ist raw); #endif /* _PROTO_HTTP_HTX_H */ diff --git a/src/cache.c b/src/cache.c index ccbbe52096..9cef0cab64 100644 --- a/src/cache.c +++ b/src/cache.c @@ -963,7 +963,7 @@ static void http_cache_io_handler(struct appctx *appctx) error: /* Sent and HTTP error 500 */ b_reset(&res->buf); - errmsg = &htx_err_chunks[HTTP_ERR_500]; + errmsg = &http_err_chunks[HTTP_ERR_500]; res->buf.data = b_data(errmsg); memcpy(res->buf.area, b_head(errmsg), b_data(errmsg)); res_htx = htx_from_buf(&res->buf); diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 1101a98e5f..cf3cb56b94 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -3832,8 +3833,17 @@ stats_error_parsing: for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { if (http_err_codes[rc] == errnum) { + struct buffer chk; + + if (!http_str_to_htx(&chk, ist2(err, errlen))) { + ha_alert("parsing [%s:%d] : unable to convert message in HTX for HTTP return code %d.\n", + file, linenum, http_err_codes[rc]); + err_code |= ERR_ALERT | ERR_FATAL; + free(err); + goto out; + } chunk_destroy(&curproxy->errmsg[rc]); - chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); + curproxy->errmsg[rc] = chk; break; } } @@ -3892,8 +3902,17 @@ stats_error_parsing: errnum = atol(args[1]); for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { if (http_err_codes[rc] == errnum) { + struct buffer chk; + + if (!http_str_to_htx(&chk, ist2(err, errlen))) { + ha_alert("parsing [%s:%d] : unable to convert message in HTX for HTTP return code %d.\n", + file, linenum, http_err_codes[rc]); + err_code |= ERR_ALERT | ERR_FATAL; + free(err); + goto out; + } chunk_destroy(&curproxy->errmsg[rc]); - chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); + curproxy->errmsg[rc] = chk; break; } } diff --git a/src/haproxy.c b/src/haproxy.c index 25256139e7..dfd2819e13 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1383,13 +1383,6 @@ static void init(int argc, char **argv) if (init_acl() != 0) exit(1); - /* warning, we init buffers later */ - if (!init_http(&err_msg)) { - ha_alert("%s. Aborting.\n", err_msg); - free(err_msg); - abort(); - } - /* Initialise lua. */ hlua_init(); diff --git a/src/hlua.c b/src/hlua.c index aca3cc9eac..fe67f045f4 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -6724,7 +6724,7 @@ static void hlua_applet_http_fct(struct appctx *ctx) * just close the connection. */ if (!(ctx->ctx.hlua_apphttp.flags & APPLET_HDR_SENT)) { - struct buffer *err = &htx_err_chunks[HTTP_ERR_500]; + struct buffer *err = &http_err_chunks[HTTP_ERR_500]; channel_erase(res); res->buf.data = b_data(err); diff --git a/src/http.c b/src/http.c index 66a4282f4d..c77f8c8bcc 100644 --- a/src/http.c +++ b/src/http.c @@ -155,11 +155,6 @@ const unsigned char http_char_classes[256] = { [127] = HTTP_FLG_CTL, }; -/* We must put the messages here since GCC cannot initialize consts depending - * on strlen(). - */ -struct buffer http_err_chunks[HTTP_ERR_SIZE]; - const struct ist HTTP_100 = IST("HTTP/1.1 100 Continue\r\n\r\n"); const struct ist HTTP_103 = IST("HTTP/1.1 103 Early Hints\r\n"); @@ -985,23 +980,3 @@ int http_parse_stline(const struct ist line, struct ist *p1, struct ist *p2, str return 1; } - - -/* post-initializes the HTTP parts. Returns zero on error, with - * pointing to the error message. - */ -int init_http(char **err) -{ - int msg; - - for (msg = 0; msg < HTTP_ERR_SIZE; msg++) { - if (!http_err_msgs[msg]) { - memprintf(err, "Internal error: no message defined for HTTP return code %d", msg); - return 0; - } - - http_err_chunks[msg].area = (char *)http_err_msgs[msg]; - http_err_chunks[msg].data = strlen(http_err_msgs[msg]); - } - return 1; -} diff --git a/src/http_ana.c b/src/http_ana.c index 9e876cdf9e..ac3412bf00 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -4904,7 +4904,7 @@ struct buffer *http_error_message(struct stream *s) else if (strm_fe(s)->errmsg[msgnum].area) return &strm_fe(s)->errmsg[msgnum]; else - return &htx_err_chunks[msgnum]; + return &http_err_chunks[msgnum]; } /* Return the error message corresponding to si->err_type. It is assumed diff --git a/src/http_htx.c b/src/http_htx.c index 3382811411..07ff191c93 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -19,7 +19,7 @@ #include -struct buffer htx_err_chunks[HTTP_ERR_SIZE]; +struct buffer http_err_chunks[HTTP_ERR_SIZE]; /* Returns the next unporocessed start line in the HTX message. It returns NULL * if the start-line is undefined (first == -1). Otherwise, it returns the @@ -600,7 +600,7 @@ unsigned int http_get_htx_fhdr(const struct htx *htx, const struct ist hdr, return 1; } -static struct htx *http_str_to_htx(struct buffer *buf, struct ist raw) +struct htx *http_str_to_htx(struct buffer *buf, struct ist raw) { struct htx *htx; struct htx_sl *sl; @@ -673,28 +673,11 @@ error: static int http_htx_init(void) { - struct proxy *px; struct buffer chk; struct ist raw; int rc; int err_code = 0; - for (px = proxies_list; px; px = px->next) { - for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { - if (!b_data(&px->errmsg[rc])) - continue; - - raw = ist2(b_head(&px->errmsg[rc]), b_data(&px->errmsg[rc])); - if (!http_str_to_htx(&chk, raw)) { - ha_alert("config: %s '%s': Unable to convert message in HTX for HTTP return code %d.\n", - proxy_type_str(px), px->id, http_err_codes[rc]); - err_code |= ERR_ALERT | ERR_FATAL; - } - chunk_destroy(&px->errmsg[rc]); - px->errmsg[rc] = chk; - } - } - for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { if (!http_err_msgs[rc]) { ha_alert("Internal error: no message defined for HTTP return code %d", rc); @@ -708,7 +691,7 @@ static int http_htx_init(void) http_err_codes[rc]); err_code |= ERR_ALERT | ERR_FATAL; } - htx_err_chunks[rc] = chk; + http_err_chunks[rc] = chk; } end: return err_code;