]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: Don't store raw HTTP errors in chunks anymore
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 17 Jul 2019 20:02:08 +0000 (22:02 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 19 Jul 2019 07:46:23 +0000 (09:46 +0200)
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.

include/common/http.h
include/proto/http_htx.h
src/cache.c
src/cfgparse-listen.c
src/haproxy.c
src/hlua.c
src/http.c
src/http_ana.c
src/http_htx.c

index b0befa5f1c0e43942f52304e35a40ab39df28f21..537be5a01acbdf149fcfaa82019fdfdf919140d6 100644 (file)
@@ -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);
index a134052234a70d13b2b3c56beb93321a3dd1e8f2..e33fdbec6f71a64b8723b7eaaff902930981503e 100644 (file)
@@ -28,7 +28,7 @@
 
 #include <types/http_htx.h>
 
-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 */
index ccbbe520963e7e14a828b20d36d3da3f741ae140..9cef0cab6405a6971da3b67bc4d0ac93add1c3a3 100644 (file)
@@ -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);
index 1101a98e5f8a481f2b0ab5eb84b1bb17b34429d9..cf3cb56b94f9551818df710f78a3d9d07c22d105 100644 (file)
@@ -20,6 +20,7 @@
 #include <proto/acl.h>
 #include <proto/checks.h>
 #include <proto/connection.h>
+#include <proto/http_htx.h>
 #include <proto/http_rules.h>
 #include <proto/listener.h>
 #include <proto/protocol.h>
@@ -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;
                        }
                }
index 25256139e798b0cf07c1caec468b837d3c0da5f2..dfd2819e1335f3b2e07ef0252d6a4247208b3b8c 100644 (file)
@@ -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();
 
index aca3cc9eaceccc937a3ef9e651281203b420bcd3..fe67f045f4a89e3197d33ce5be2d93004ae5e3b3 100644 (file)
@@ -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);
index 66a4282f4d42d993a2229b749f133726c98b18d3..c77f8c8bcc25cf41b31397362e774d31425c82e0 100644 (file)
@@ -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 <err>
- * 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;
-}
index 9e876cdf9e22715883843e79c4100f24013c52be..ac3412bf005246204cd5e699de29027988965317 100644 (file)
@@ -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
index 3382811411b77a0419e63a523c6a63e0156b21ef..07ff191c93afbe49bda2d0b595e2ceca372630b0 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <proto/http_htx.h>
 
-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;