]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: Add support for HTTP 414/431 status codes
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 18 Nov 2024 21:06:17 +0000 (22:06 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 19 Nov 2024 14:29:40 +0000 (15:29 +0100)
414-Uri-Too-Long and 431-Request-Header-Fields-Too-Large are now part of
supported status codes that can be define as error files. The hash table
defined in http_get_status_idx() was updated accordingly.

doc/configuration.txt
include/haproxy/http-t.h
src/http.c

index e6ec7bd2c6e286a60a8f3648ea5ee73f6d552c23..f81cca68b5ad436abc25debf9e672022839bfa45 100644 (file)
@@ -6912,7 +6912,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,
-              413, 425, 429, 500, 501, 502, 503, and 504.
+              413, 414, 425, 429, 431, 500, 501, 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
@@ -6965,8 +6965,8 @@ 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, 413, 425, 429, 500, 501, 502, 503,
-            and 504.
+            403, 404, 405, 407, 408, 410, 413, 414, 425, 429, 431, 500, 501,
+            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
@@ -6996,7 +6996,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,
-              413, 425, 429, 500, 501, 502, 503, and 504.
+              413, 414, 425, 429, 431, 500, 501, 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,
@@ -7032,7 +7032,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,
-              413, 425, 429, 500, 501, 502, 503, and 504.
+              413, 414, 425, 429, 431, 500, 501, 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,
@@ -8002,8 +8002,8 @@ http-error status <code> [content-type <type>]
   Arguments :
     status <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, 413, 425,
-                         429, 500, 501, 502, 503, and 504.
+                         200, 400, 401, 403, 404, 405, 407, 408, 410, 413,
+                         414, 425, 429, 431, 500, 501, 502, 503, and 504.
 
     content-type <type>  is the response content type, for instance
                          "text/plain". This parameter is ignored and should be
@@ -15530,21 +15530,22 @@ 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 HAProxy (200, 400, 403, 404, 405, 408, 410, 413,
-    425, 429, 500, 501, 502, 503, and 504). The "content-type" argument, if
-    any, is ignored.
+    414, 425, 429, 431, 500, 501, 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 HAProxy (200, 400, 403, 404, 405, 408, 410, 413, 425, 429, 500, 501,
-    502, 503, and 504). The "content-type" argument, if any, is ignored.
+    by HAProxy (200, 400, 403, 404, 405, 408, 410, 413, 414, 425, 429, 431,
+    500, 501, 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 HAProxy (200, 400, 403, 404, 405,
-    408, 410, 413, 425, 429, 500, 501, 502, 503, and 504). The "content-type"
-    argument, if any, is ignored.
+    408, 410, 413, 414, 425, 429, 431, 500, 501, 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
index 3165082f9e5a616569d088a2e6d9f089ecc553a5..5703f38b1c1b1bd62796e70e44879d6fd63098af 100644 (file)
@@ -92,10 +92,12 @@ enum {
        HTTP_ERR_408,
        HTTP_ERR_410,
        HTTP_ERR_413,
+       HTTP_ERR_414,
        HTTP_ERR_421,
        HTTP_ERR_422,
        HTTP_ERR_425,
        HTTP_ERR_429,
+       HTTP_ERR_431,
        HTTP_ERR_500,
        HTTP_ERR_501,
        HTTP_ERR_502,
index 8c94dfb3644202d26e565ec240a9c4875939da9e..10522206d06c09a0f2cf1159b57eb66702503159 100644 (file)
@@ -167,10 +167,12 @@ const int http_err_codes[HTTP_ERR_SIZE] = {
        [HTTP_ERR_408] = 408,
        [HTTP_ERR_410] = 410,
        [HTTP_ERR_413] = 413,
+       [HTTP_ERR_414] = 414,
        [HTTP_ERR_421] = 421,
        [HTTP_ERR_422] = 422,
        [HTTP_ERR_425] = 425,
        [HTTP_ERR_429] = 429,
+       [HTTP_ERR_431] = 431,
        [HTTP_ERR_500] = 500,
        [HTTP_ERR_501] = 501,
        [HTTP_ERR_502] = 502,
@@ -261,6 +263,14 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = {
        "\r\n"
        "<html><body><h1>413 Payload Too Large</h1>\nThe request entity exceeds the maximum allowed.\n</body></html>\n",
 
+       [HTTP_ERR_414] =
+       "HTTP/1.1 414 URI Too Long\r\n"
+       "Content-length: 110\r\n"
+       "Cache-Control: no-cache\r\n"
+       "Content-Type: text/html\r\n"
+       "\r\n"
+       "<html><body><h1>414 URI Too Long</h1>\nThe URI provided was too long for the server to process.\n</body></html>\n",
+
        [HTTP_ERR_421] =
        "HTTP/1.1 421 Misdirected Request\r\n"
        "Content-length: 104\r\n"
@@ -293,6 +303,14 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = {
        "\r\n"
        "<html><body><h1>429 Too Many Requests</h1>\nYou have sent too many requests in a given amount of time.\n</body></html>\n",
 
+       [HTTP_ERR_431] =
+       "HTTP/1.1 431 Request Header Fields 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>431 Request Header Fields Too Large</h1>\n>Request Header Fields Too Large.\n</body></html>\n",
+
        [HTTP_ERR_500] =
        "HTTP/1.1 500 Internal Server Error\r\n"
        "Content-length: 97\r\n"
@@ -379,20 +397,20 @@ int http_get_status_idx(unsigned int status)
 {
        /* This table was built using dev/phash and easily finds solutions up
         * to 21 different entries and produces much better code with 32
-        * (padded with err 500 below as it's the default, though only [19] is
+        * (padded with err 500 below as it's the default, though only [7] is
         * the real one).
         */
        const uchar codes[32] = {
-               HTTP_ERR_408, HTTP_ERR_200, HTTP_ERR_504, HTTP_ERR_400,
-               HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_401, HTTP_ERR_410,
-               HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_500,
-               HTTP_ERR_500, HTTP_ERR_429, HTTP_ERR_403, HTTP_ERR_500,
-               HTTP_ERR_421, HTTP_ERR_404, HTTP_ERR_413, HTTP_ERR_500,
-               HTTP_ERR_422, HTTP_ERR_405, HTTP_ERR_500, HTTP_ERR_501,
-               HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_502,
-               HTTP_ERR_407, HTTP_ERR_500, HTTP_ERR_503, HTTP_ERR_425,
+               HTTP_ERR_500, HTTP_ERR_502, HTTP_ERR_429, HTTP_ERR_500,
+               HTTP_ERR_414, HTTP_ERR_404, HTTP_ERR_500, HTTP_ERR_500,
+               HTTP_ERR_500, HTTP_ERR_200, HTTP_ERR_422, HTTP_ERR_407,
+               HTTP_ERR_500, HTTP_ERR_503, HTTP_ERR_500, HTTP_ERR_500,
+               HTTP_ERR_425, HTTP_ERR_410, HTTP_ERR_405, HTTP_ERR_400,
+               HTTP_ERR_501, HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_413,
+               HTTP_ERR_408, HTTP_ERR_403, HTTP_ERR_504, HTTP_ERR_500,
+               HTTP_ERR_431, HTTP_ERR_421, HTTP_ERR_500, HTTP_ERR_401,
        };
-       uint hash = ((status * 118) >> 5) % 32;
+       uint hash = ((status * 406) >> 5) % 32;
        uint ret  = codes[hash];
 
        if (http_err_codes[ret] == status)