]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: http: Add support for HTTP 411 status code
authorWilly Tarreau <w@1wt.eu>
Mon, 23 Nov 2026 14:46:22 +0000 (15:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 23 Nov 2026 22:24:23 +0000 (23:24 +0100)
411-Length-Required is now part of supported status codes that
can be defined as error files. The hash table defined in
http_get_status_idx() was updated accordingly (the factor 406 did
not change).

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

index 06f2989e5c50552495639a4e98beeae1e5927bd2..8d1acfc0acd7eecc5394b1ad50ee05006dcb7418 100644 (file)
@@ -17,9 +17,9 @@
 //const int codes[CODES] = { 200,400,401,403,404,405,407,408,410,413,421,422,425,429,500,501,502,503,504};
 
 #define CODES 32
-const int codes[CODES] = { 200,400,401,403,404,405,407,408,410,413,414,421,422,425,429,431,500,501,502,503,504,
+const int codes[CODES] = { 200,400,401,403,404,405,407,408,410,411,413,414,421,422,425,429,431,500,501,502,503,504,
        /* padding entries below, which will fall back to the default code */
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
+       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
 
 unsigned mul, xor;
 unsigned bmul = 0, bxor = 0;
index b69e68c61ce9874c825b2ae219527e9d992f34d8..0fd15bbe6a36b0152eefea578708d058a5a18858 100644 (file)
@@ -8170,7 +8170,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, 414, 425, 429, 431, 500, 501, 502, 503, and 504.
+              411, 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
@@ -8223,8 +8223,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, 414, 425, 429, 431, 500, 501,
-            502, 503, and 504.
+            403, 404, 405, 407, 408, 410, 411, 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
@@ -8254,7 +8254,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, 414, 425, 429, 431, 500, 501, 502, 503, and 504.
+              411, 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,
@@ -8290,7 +8290,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, 414, 425, 429, 431, 500, 501, 502, 503, and 504.
+              411, 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,
@@ -9610,7 +9610,7 @@ 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,
+                         200, 400, 401, 403, 404, 405, 407, 408, 410, 411, 413,
                          414, 425, 429, 431, 500, 501, 502, 503, and 504.
 
     content-type <type>  is the response content type, for instance
@@ -17166,23 +17166,23 @@ 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,
-    414, 425, 429, 431, 500, 501, 502, 503, and 504). The "content-type"
+    status code handled by HAProxy (200, 400, 403, 404, 405, 408, 410, 411,
+    413, 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, 414, 425, 429, 431,
-    500, 501, 502, 503, and 504). The "content-type" argument, if any, is
+    by HAProxy (200, 400, 403, 404, 405, 408, 410, 411, 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, 414, 425, 429, 431, 500, 501, 502, 503, and 504).
-    The "content-type" argument, if any, is ignored.
+    408, 410, 411, 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 f221ad12941d017f7fff62946909bedba66d8360..96946c78fd1517adadadbc94e1f6809e70115c73 100644 (file)
@@ -96,6 +96,7 @@ enum {
        HTTP_ERR_407,
        HTTP_ERR_408,
        HTTP_ERR_410,
+       HTTP_ERR_411,
        HTTP_ERR_413,
        HTTP_ERR_414,
        HTTP_ERR_421,
index 3693738cfb803f442abd78cb92db3f872e183d1e..bd9e96315028c0478a212727802bdfd4315543b0 100644 (file)
@@ -171,6 +171,7 @@ const int http_err_codes[HTTP_ERR_SIZE] = {
        [HTTP_ERR_407] = 407,
        [HTTP_ERR_408] = 408,
        [HTTP_ERR_410] = 410,
+       [HTTP_ERR_411] = 411,
        [HTTP_ERR_413] = 413,
        [HTTP_ERR_414] = 414,
        [HTTP_ERR_421] = 421,
@@ -260,6 +261,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_411] =
+       "HTTP/1.1 411 Length Required\r\n"
+       "Content-length: 115\r\n"
+       "Cache-Control: no-cache\r\n"
+       "Content-Type: text/html\r\n"
+       "\r\n"
+       "<html><body><h1>411 Length Required</h1>\nThe request was sent without a required length indication.\n</body></html>\n",
+
        [HTTP_ERR_413] =
        "HTTP/1.1 413 Payload Too Large\r\n"
        "Content-length: 106\r\n"
@@ -406,19 +415,19 @@ enum http_meth_t find_http_meth(const char *str, const int len)
 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
+        * to 22 different entries and produces much better code with 32
         * (padded with err 500 below as it's the default, though only [7] is
         * the real one).
         */
        const uchar codes[32] = {
-               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,
+               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_411, HTTP_ERR_401,
        };
        uint hash = ((status * 406) >> 5) % 32;
        uint ret  = codes[hash];