Skip to content

Commit 62dc875

Browse files
committed
MINOR: http: Add support for HTTP 414/431 status codes
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.
1 parent 18de419 commit 62dc875

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

doc/configuration.txt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6912,7 +6912,7 @@ errorfile <code> <file>
69126912
Arguments :
69136913
<code> is the HTTP status code. Currently, HAProxy is capable of
69146914
generating codes 200, 400, 401, 403, 404, 405, 407, 408, 410,
6915-
413, 425, 429, 500, 501, 502, 503, and 504.
6915+
413, 414, 425, 429, 431, 500, 501, 502, 503, and 504.
69166916

69176917
<file> designates a file containing the full HTTP response. It is
69186918
recommended to follow the common practice of appending ".http" to
@@ -6965,8 +6965,8 @@ errorfiles <name> [<code> ...]
69656965

69666966
<code> is a HTTP status code. Several status code may be listed.
69676967
Currently, HAProxy is capable of generating codes 200, 400, 401,
6968-
403, 404, 405, 407, 408, 410, 413, 425, 429, 500, 501, 502, 503,
6969-
and 504.
6968+
403, 404, 405, 407, 408, 410, 413, 414, 425, 429, 431, 500, 501,
6969+
502, 503, and 504.
69706970

69716971
Errors defined in the http-errors section with the name <name> are imported
69726972
in the current proxy. If no status code is specified, all error files of the
@@ -6996,7 +6996,7 @@ errorloc302 <code> <url>
69966996
Arguments :
69976997
<code> is the HTTP status code. Currently, HAProxy is capable of
69986998
generating codes 200, 400, 401, 403, 404, 405, 407, 408, 410,
6999-
413, 425, 429, 500, 501, 502, 503, and 504.
6999+
413, 414, 425, 429, 431, 500, 501, 502, 503, and 504.
70007000

70017001
<url> it is the exact contents of the "Location" header. It may contain
70027002
either a relative URI to an error page hosted on the same site,
@@ -7032,7 +7032,7 @@ errorloc303 <code> <url>
70327032
Arguments :
70337033
<code> is the HTTP status code. Currently, HAProxy is capable of
70347034
generating codes 200, 400, 401, 403, 404, 405, 407, 408, 410,
7035-
413, 425, 429, 500, 501, 502, 503, and 504.
7035+
413, 414, 425, 429, 431, 500, 501, 502, 503, and 504.
70367036

70377037
<url> it is the exact contents of the "Location" header. It may contain
70387038
either a relative URI to an error page hosted on the same site,
@@ -8002,8 +8002,8 @@ http-error status <code> [content-type <type>]
80028002
Arguments :
80038003
status <code> is the HTTP status code. It must be specified.
80048004
Currently, HAProxy is capable of generating codes
8005-
200, 400, 401, 403, 404, 405, 407, 408, 410, 413, 425,
8006-
429, 500, 501, 502, 503, and 504.
8005+
200, 400, 401, 403, 404, 405, 407, 408, 410, 413,
8006+
414, 425, 429, 431, 500, 501, 502, 503, and 504.
80078007

80088008
content-type <type> is the response content type, for instance
80098009
"text/plain". This parameter is ignored and should be
@@ -15530,21 +15530,22 @@ return [ status <code> ] [ content-type <type> ]
1553015530
* If "default-errorfiles" argument is set, the proxy's errorfiles are
1553115531
considered. If the "status" argument is defined, it must be one of the
1553215532
status code handled by HAProxy (200, 400, 403, 404, 405, 408, 410, 413,
15533-
425, 429, 500, 501, 502, 503, and 504). The "content-type" argument, if
15534-
any, is ignored.
15533+
414, 425, 429, 431, 500, 501, 502, 503, and 504). The "content-type"
15534+
argument, if any, is ignored.
1553515535

1553615536
* If a specific errorfile is defined, with an "errorfile" argument, the
1553715537
corresponding file, containing a full HTTP response, is returned. Only the
1553815538
"status" argument is considered. It must be one of the status code handled
15539-
by HAProxy (200, 400, 403, 404, 405, 408, 410, 413, 425, 429, 500, 501,
15540-
502, 503, and 504). The "content-type" argument, if any, is ignored.
15539+
by HAProxy (200, 400, 403, 404, 405, 408, 410, 413, 414, 425, 429, 431,
15540+
500, 501, 502, 503, and 504). The "content-type" argument, if any, is
15541+
ignored.
1554115542

1554215543
* If an http-errors section is defined, with an "errorfiles" argument, the
1554315544
corresponding file in the specified http-errors section, containing a full
1554415545
HTTP response, is returned. Only the "status" argument is considered. It
1554515546
must be one of the status code handled by HAProxy (200, 400, 403, 404, 405,
15546-
408, 410, 413, 425, 429, 500, 501, 502, 503, and 504). The "content-type"
15547-
argument, if any, is ignored.
15547+
408, 410, 413, 414, 425, 429, 431, 500, 501, 502, 503, and 504).
15548+
The "content-type" argument, if any, is ignored.
1554815549

1554915550
* If a "file" or a "lf-file" argument is specified, the file's content is
1555015551
used as the response payload. If the file is not empty, its content-type

include/haproxy/http-t.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ enum {
9292
HTTP_ERR_408,
9393
HTTP_ERR_410,
9494
HTTP_ERR_413,
95+
HTTP_ERR_414,
9596
HTTP_ERR_421,
9697
HTTP_ERR_422,
9798
HTTP_ERR_425,
9899
HTTP_ERR_429,
100+
HTTP_ERR_431,
99101
HTTP_ERR_500,
100102
HTTP_ERR_501,
101103
HTTP_ERR_502,

src/http.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ const int http_err_codes[HTTP_ERR_SIZE] = {
167167
[HTTP_ERR_408] = 408,
168168
[HTTP_ERR_410] = 410,
169169
[HTTP_ERR_413] = 413,
170+
[HTTP_ERR_414] = 414,
170171
[HTTP_ERR_421] = 421,
171172
[HTTP_ERR_422] = 422,
172173
[HTTP_ERR_425] = 425,
173174
[HTTP_ERR_429] = 429,
175+
[HTTP_ERR_431] = 431,
174176
[HTTP_ERR_500] = 500,
175177
[HTTP_ERR_501] = 501,
176178
[HTTP_ERR_502] = 502,
@@ -261,6 +263,14 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = {
261263
"\r\n"
262264
"<html><body><h1>413 Payload Too Large</h1>\nThe request entity exceeds the maximum allowed.\n</body></html>\n",
263265

266+
[HTTP_ERR_414] =
267+
"HTTP/1.1 414 URI Too Long\r\n"
268+
"Content-length: 110\r\n"
269+
"Cache-Control: no-cache\r\n"
270+
"Content-Type: text/html\r\n"
271+
"\r\n"
272+
"<html><body><h1>414 URI Too Long</h1>\nThe URI provided was too long for the server to process.\n</body></html>\n",
273+
264274
[HTTP_ERR_421] =
265275
"HTTP/1.1 421 Misdirected Request\r\n"
266276
"Content-length: 104\r\n"
@@ -293,6 +303,14 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = {
293303
"\r\n"
294304
"<html><body><h1>429 Too Many Requests</h1>\nYou have sent too many requests in a given amount of time.\n</body></html>\n",
295305

306+
[HTTP_ERR_431] =
307+
"HTTP/1.1 431 Request Header Fields Too Large\r\n"
308+
"Content-length: 106\r\n"
309+
"Cache-Control: no-cache\r\n"
310+
"Content-Type: text/html\r\n"
311+
"\r\n"
312+
"<html><body><h1>431 Request Header Fields Too Large</h1>\n>Request Header Fields Too Large.\n</body></html>\n",
313+
296314
[HTTP_ERR_500] =
297315
"HTTP/1.1 500 Internal Server Error\r\n"
298316
"Content-length: 97\r\n"
@@ -379,20 +397,20 @@ int http_get_status_idx(unsigned int status)
379397
{
380398
/* This table was built using dev/phash and easily finds solutions up
381399
* to 21 different entries and produces much better code with 32
382-
* (padded with err 500 below as it's the default, though only [19] is
400+
* (padded with err 500 below as it's the default, though only [7] is
383401
* the real one).
384402
*/
385403
const uchar codes[32] = {
386-
HTTP_ERR_408, HTTP_ERR_200, HTTP_ERR_504, HTTP_ERR_400,
387-
HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_401, HTTP_ERR_410,
388-
HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_500,
389-
HTTP_ERR_500, HTTP_ERR_429, HTTP_ERR_403, HTTP_ERR_500,
390-
HTTP_ERR_421, HTTP_ERR_404, HTTP_ERR_413, HTTP_ERR_500,
391-
HTTP_ERR_422, HTTP_ERR_405, HTTP_ERR_500, HTTP_ERR_501,
392-
HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_502,
393-
HTTP_ERR_407, HTTP_ERR_500, HTTP_ERR_503, HTTP_ERR_425,
404+
HTTP_ERR_500, HTTP_ERR_502, HTTP_ERR_429, HTTP_ERR_500,
405+
HTTP_ERR_414, HTTP_ERR_404, HTTP_ERR_500, HTTP_ERR_500,
406+
HTTP_ERR_500, HTTP_ERR_200, HTTP_ERR_422, HTTP_ERR_407,
407+
HTTP_ERR_500, HTTP_ERR_503, HTTP_ERR_500, HTTP_ERR_500,
408+
HTTP_ERR_425, HTTP_ERR_410, HTTP_ERR_405, HTTP_ERR_400,
409+
HTTP_ERR_501, HTTP_ERR_500, HTTP_ERR_500, HTTP_ERR_413,
410+
HTTP_ERR_408, HTTP_ERR_403, HTTP_ERR_504, HTTP_ERR_500,
411+
HTTP_ERR_431, HTTP_ERR_421, HTTP_ERR_500, HTTP_ERR_401,
394412
};
395-
uint hash = ((status * 118) >> 5) % 32;
413+
uint hash = ((status * 406) >> 5) % 32;
396414
uint ret = codes[hash];
397415

398416
if (http_err_codes[ret] == status)

0 commit comments

Comments
 (0)