Hi!
On Mon, Jun 22, 2020 at 09:17:01AM +0200, Anthonin Bonnefoy wrote:
> From: Anthonin Bonnefoy <[email protected]>
>
> Add 413 http status code. This will allow 413 to be used in deny_status
> and errorfile.
Good idea! When I first met this status code I thought we were missing
it but forgot to add it. In the same vein, there was the 431 that I wanted
to add for too large header blocks. We might have to put that into the
todo list (issue tracker).
Applied, thanks!
Willy
> ---
> doc/configuration.txt | 40 ++++++++++++++++++++--------------------
> include/haproxy/http-t.h | 1 +
> src/http.c | 10 ++++++++++
> 3 files changed, 31 insertions(+), 20 deletions(-)
>
> diff --git a/doc/configuration.txt b/doc/configuration.txt
> index a2ba7cf93..632408747 100644
> --- a/doc/configuration.txt
> +++ b/doc/configuration.txt
> @@ -3913,7 +3913,7 @@ errorfile <code> <file>
> Arguments :
> <code> is the HTTP status code. Currently, HAProxy is capable of
> generating codes 200, 400, 401, 403, 404, 405, 407, 408, 410,
> - 425, 429, 500, 502, 503, and 504.
> + 413, 425, 429, 500, 502, 503, and 504.
>
> <file> designates a file containing the full HTTP response. It is
> recommended to follow the common practice of appending ".http"
> to
> @@ -3962,7 +3962,7 @@ errorfiles <name> [<code> ...]
>
> <code> is a HTTP status code. Several status code may be listed.
> Currently, HAProxy is capable of generating codes 200, 400, 401,
> - 403, 404, 405, 407, 408, 410, 425, 429, 500, 502, 503, and 504.
> + 403, 404, 405, 407, 408, 410, 413, 425, 429, 500, 502, 503, and
> 504.
>
> Errors defined in the http-errors section with the name <name> are imported
> in the current proxy. If no status code is specified, all error files of
> the
> @@ -3988,7 +3988,7 @@ errorloc302 <code> <url>
> Arguments :
> <code> is the HTTP status code. Currently, HAProxy is capable of
> generating codes 200, 400, 401, 403, 404, 405, 407, 408, 410,
> - 425, 429, 500, 502, 503, and 504.
> + 413, 425, 429, 500, 502, 503, and 504.
>
> <url> it is the exact contents of the "Location" header. It may
> contain
> either a relative URI to an error page hosted on the same site,
> @@ -4020,7 +4020,7 @@ errorloc303 <code> <url>
> Arguments :
> <code> is the HTTP status code. Currently, HAProxy is capable of
> generating codes 200, 400, 401, 403, 404, 405, 407, 408, 410,
> - 425, 429, 500, 502, 503, and 504.
> + 413, 425, 429, 500, 502, 503, and 504.
>
> <url> it is the exact contents of the "Location" header. It may
> contain
> either a relative URI to an error page hosted on the same site,
> @@ -4995,8 +4995,8 @@ http-error status <code> [content-type <type>]
> Arguments :
> staus <code> is the HTTP status code. It must be specified.
> Currently, HAProxy is capable of generating codes
> - 200, 400, 401, 403, 404, 405, 407, 408, 410, 425,
> 429,
> - 500, 502, 503, and 504.
> + 200, 400, 401, 403, 404, 405, 407, 408, 410, 413,
> 425,
> + 429, 500, 502, 503, and 504.
>
> content-type <type> is the response content type, for instance
> "text/plain". This parameter is ignored and should
> be
> @@ -5439,22 +5439,22 @@ http-request return [status <code>] [content-type
> <type>]
>
> * If "default-errorfiles" argument is set, the proxy's errorfiles are
> considered. If the "status" argument is defined, it must be one of the
> - status code handled by hparoxy (200, 400, 403, 404, 405, 408, 410, 425,
> - 429, 500, 502, 503, and 504). The "content-type" argument, if any, is
> - ignored.
> + status code handled by hparoxy (200, 400, 403, 404, 405, 408, 410, 413,
> + 425, 429, 500, 502, 503, and 504). The "content-type" argument, if any,
> + is ignored.
>
> * If a specific errorfile is defined, with an "errorfile" argument, the
> corresponding file, containing a full HTTP response, is returned. Only
> the
> "status" argument is considered. It must be one of the status code
> handled
> - by hparoxy (200, 400, 403, 404, 405, 408, 410, 425, 429, 500, 502, 503,
> and
> - 504). The "content-type" argument, if any, is ignored.
> + by hparoxy (200, 400, 403, 404, 405, 408, 410, 413, 425, 429, 500, 502,
> 503,
> + and 504). The "content-type" argument, if any, is ignored.
>
> * If an http-errors section is defined, with an "errorfiles" argument, the
> corresponding file in the specified http-errors section, containing a
> full
> HTTP response, is returned. Only the "status" argument is considered. It
> must be one of the status code handled by hparoxy (200, 400, 403, 404,
> 405,
> - 408, 410, 425, 429, 500, 502, 503, and 504). The "content-type" argument,
> - if any, is ignored.
> + 408, 410, 413, 425, 429, 500, 502, 503, and 504). The "content-type"
> + argument, if any, is ignored.
>
> * If a "file" or a "lf-file" argument is specified, the file's content is
> used as the response payload. If the file is not empty, its content-type
> @@ -6086,22 +6086,22 @@ http-response return [status <code>] [content-type
> <type>]
>
> * If "default-errorfiles" argument is set, the proxy's errorfiles are
> considered. If the "status" argument is defined, it must be one of the
> - status code handled by hparoxy (200, 400, 403, 404, 405, 408, 410, 425,
> - 429, 500, 502, 503, and 504). The "content-type" argument, if any, is
> - ignored.
> + status code handled by hparoxy (200, 400, 403, 404, 405, 408, 410, 413,
> + 425, 429, 500, 502, 503, and 504). The "content-type" argument, if any,
> + is ignored.
>
> * If a specific errorfile is defined, with an "errorfile" argument, the
> corresponding file, containing a full HTTP response, is returned. Only
> the
> "status" argument is considered. It must be one of the status code
> handled
> - by hparoxy (200, 400, 403, 404, 405, 408, 410, 425, 429, 500, 502, 503,
> and
> - 504). The "content-type" argument, if any, is ignored.
> + by hparoxy (200, 400, 403, 404, 405, 408, 410, 413, 425, 429, 500, 502,
> 503,
> + and 504). The "content-type" argument, if any, is ignored.
>
> * If an http-errors section is defined, with an "errorfiles" argument, the
> corresponding file in the specified http-errors section, containing a
> full
> HTTP response, is returned. Only the "status" argument is considered. It
> must be one of the status code handled by hparoxy (200, 400, 403, 404,
> 405,
> - 408, 410, 425, 429, 500, 502, 503, and 504). The "content-type" argument,
> - if any, is ignored.
> + 408, 410, 413, 425, 429, 500, 502, 503, and 504). The "content-type"
> + argument, if any, is ignored.
>
> * If a "file" or a "lf-file" argument is specified, the file's content is
> used as the response payload. If the file is not empty, its content-type
> diff --git a/include/haproxy/http-t.h b/include/haproxy/http-t.h
> index c8bf9a308..500fc46d5 100644
> --- a/include/haproxy/http-t.h
> +++ b/include/haproxy/http-t.h
> @@ -90,6 +90,7 @@ enum {
> HTTP_ERR_407,
> HTTP_ERR_408,
> HTTP_ERR_410,
> + HTTP_ERR_413,
> HTTP_ERR_421,
> HTTP_ERR_425,
> HTTP_ERR_429,
> diff --git a/src/http.c b/src/http.c
> index b798c5db9..7278cad58 100644
> --- a/src/http.c
> +++ b/src/http.c
> @@ -165,6 +165,7 @@ const int http_err_codes[HTTP_ERR_SIZE] = {
> [HTTP_ERR_407] = 407,
> [HTTP_ERR_408] = 408,
> [HTTP_ERR_410] = 410,
> + [HTTP_ERR_413] = 413,
> [HTTP_ERR_421] = 421,
> [HTTP_ERR_425] = 425,
> [HTTP_ERR_429] = 429,
> @@ -249,6 +250,14 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = {
> "\r\n"
> "<html><body><h1>410 Gone</h1>\nThe resource is no longer available and
> will not be available again.\n</body></html>\n",
>
> + [HTTP_ERR_413] =
> + "HTTP/1.1 413 Payload Too Large\r\n"
> + "Content-length: 106\r\n"
> + "Cache-Control: no-cache\r\n"
> + "Content-Type: text/html\r\n"
> + "\r\n"
> + "<html><body><h1>413 Payload Too Large</h1>\nThe request entity exceeds
> the maximum allowed.\n</body></html>\n",
> +
> [HTTP_ERR_421] =
> "HTTP/1.1 421 Misdirected Request\r\n"
> "Content-length: 104\r\n"
> @@ -351,6 +360,7 @@ int http_get_status_idx(unsigned int status)
> case 407: return HTTP_ERR_407;
> case 408: return HTTP_ERR_408;
> case 410: return HTTP_ERR_410;
> + case 413: return HTTP_ERR_413;
> case 421: return HTTP_ERR_421;
> case 425: return HTTP_ERR_425;
> case 429: return HTTP_ERR_429;
> --
> 2.19.1
>