MINOR: http: Add support for http 413 status
authorAnthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Mon, 22 Jun 2020 07:17:01 +0000 (09:17 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 7 Jul 2020 13:09:27 +0000 (15:09 +0200)
Add 413 http "payload too large" status code. This will allow 413 to be
used in deny_status and errorfile.

(cherry picked from commit 85048f80c9c1ca22732951e83c01ab0b31f5371f)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

[Cf: A "connection: close" has been added in the HTTP message to be consistent
     with other error codes]

doc/configuration.txt
include/common/http.h
src/http.c

index d2e7f3e..bf55f90 100644 (file)
@@ -3601,8 +3601,8 @@ errorfile <code> <file>
                                  yes   |    yes   |   yes  |   yes
   Arguments :
     <code>    is the HTTP status code. Currently, HAProxy is capable of
-              generating codes 200, 400, 403, 404, 405, 408, 410, 425, 429, 500,
-              502, 503, and 504.
+              generating codes 200, 400, 403, 404, 405, 408, 410, 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
@@ -3650,8 +3650,8 @@ errorloc302 <code> <url>
                                  yes   |    yes   |   yes  |   yes
   Arguments :
     <code>    is the HTTP status code. Currently, HAProxy is capable of
-              generating codes 200, 400, 403, 404, 405, 408, 410, 425, 429, 500,
-              502, 503, and 504.
+              generating codes 200, 400, 403, 404, 405, 408, 410, 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,
@@ -3682,8 +3682,8 @@ errorloc303 <code> <url>
                                  yes   |    yes   |   yes  |   yes
   Arguments :
     <code>    is the HTTP status code. Currently, HAProxy is capable of
-              generating codes 200, 400, 403, 404, 405, 408, 410, 425, 429, 500,
-              502, 503, and 504.
+              generating codes 200, 400, 403, 404, 405, 408, 410, 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,
index d3519bc..db0c3ac 100644 (file)
@@ -87,6 +87,7 @@ enum {
        HTTP_ERR_405,
        HTTP_ERR_408,
        HTTP_ERR_410,
+       HTTP_ERR_413,
        HTTP_ERR_421,
        HTTP_ERR_425,
        HTTP_ERR_429,
index 8e17bed..cdd8af3 100644 (file)
@@ -220,6 +220,7 @@ const int http_err_codes[HTTP_ERR_SIZE] = {
        [HTTP_ERR_405] = 405,
        [HTTP_ERR_408] = 408,
        [HTTP_ERR_410] = 410,
+       [HTTP_ERR_413] = 413,
        [HTTP_ERR_421] = 421,
        [HTTP_ERR_425] = 425,
        [HTTP_ERR_429] = 429,
@@ -293,6 +294,15 @@ 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"
+       "Connection: close\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"
@@ -401,6 +411,7 @@ int http_get_status_idx(unsigned int status)
        case 405: return HTTP_ERR_405;
        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;