]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http_htx: Support empty errorfiles
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 22 Jul 2019 14:49:30 +0000 (16:49 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 23 Jul 2019 12:58:32 +0000 (14:58 +0200)
Empty error files may be used to disable the sending of any message for specific
error codes. A common use-case is to use the file "/dev/null". This way the
default error message is overridden and no message is returned to the client. It
was supported in the legacy HTTP mode, but not in HTX. Because of a bug, such
messages triggered an error.

This patch must be backported to 2.0 and 1.9. However, the patch will have to be
adapted.

include/proto/http_htx.h
src/http_htx.c

index e33fdbec6f71a64b8723b7eaaff902930981503e..26df97f27ade7e08728cc60e3180e578759f72ab 100644 (file)
@@ -47,6 +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);
+int http_str_to_htx(struct buffer *buf, struct ist raw);
 
 #endif /* _PROTO_HTTP_HTX_H */
index 07ff191c93afbe49bda2d0b595e2ceca372630b0..7f4f7e9a6fc3d21f5fa619f139ee5f8e2a0d7c55 100644 (file)
@@ -600,7 +600,7 @@ unsigned int http_get_htx_fhdr(const struct htx *htx, const struct ist hdr,
        return 1;
 }
 
-struct htx *http_str_to_htx(struct buffer *buf, struct ist raw)
+int http_str_to_htx(struct buffer *buf, struct ist raw)
 {
        struct htx *htx;
        struct htx_sl *sl;
@@ -610,11 +610,17 @@ struct htx *http_str_to_htx(struct buffer *buf, struct ist raw)
        unsigned int flags = HTX_SL_F_IS_RESP;
        int ret = 0;
 
+       b_reset(buf);
+       if (!raw.len) {
+               buf->size = 0;
+               buf->area = malloc(raw.len);
+               return 1;
+       }
+
        buf->size = global.tune.bufsize;
        buf->area = (char *)malloc(buf->size);
        if (!buf->area)
                goto error;
-       b_reset(buf);
 
        h1m_init_res(&h1m);
        h1m.flags |= H1_MF_NO_PHDR;
@@ -663,12 +669,12 @@ struct htx *http_str_to_htx(struct buffer *buf, struct ist raw)
        if (!htx_add_endof(htx, HTX_BLK_EOM))
                goto error;
 
-       return htx;
+       return 1;
 
 error:
        if (buf->size)
                free(buf->area);
-       return NULL;
+       return 0;
 }
 
 static int http_htx_init(void)