Welcome! Log In Create A New Profile

Advanced

[PATCH]add new http status code

Simon Liu
May 08, 2012 08:12AM
Hello!

It add a few of new http status code In RFC 6585(
http://tools.ietf.org/html/rfc6585), and so I add this to Nginx.

The new http status code 429(Too Many Requests) and 431(Request Header
Fields Too Large) in RFC 6585 is useful to Nginx,
because Nginx will return 400 when request header is Too Large and return
503 when too many request(in limit_req).

Blew is patch(for Nginx trunk) to use 429 replace 400 when request header
is too large,
and use 431 replace 503 when find too many request(limit_req module). in
addition to add new http status code 511.

Thanks!

Index: src/http/ngx_http_special_response.c
===================================================================
--- src/http/ngx_http_special_response.c (revision 4615)
+++ src/http/ngx_http_special_response.c (working copy)
@@ -210,13 +210,21 @@
;


-static char ngx_http_error_494_page[] =
+static char ngx_http_error_429_page[] =
"<html>" CRLF
-"<head><title>400 Request Header Or Cookie Too Large</title></head>"
+"<head><title>429 Too Many Requests</title></head>" CRLF
+"<body bgcolor=\"white\">" CRLF
+"<center><h1>429 Too Many Requests</h1></center>" CRLF
+;
+
+
+static char ngx_http_error_431_page[] =
+"<html>" CRLF
+"<head><title>431 Request Header Fields Too Large</title></head>"
CRLF
"<body bgcolor=\"white\">" CRLF
-"<center><h1>400 Bad Request</h1></center>" CRLF
-"<center>Request Header Or Cookie Too Large</center>" CRLF
+"<h1>431 Request Header Fields Too Large</h1>" CRLF
+"<p>request header fields too large."
;


@@ -298,6 +306,16 @@
;


+static char ngx_http_error_511_page[] =
+"<html>" CRLF
+"<head><title>511 Network Authentication Required</title></head>" CRLF
+"<body bgcolor=\"white\">" CRLF
+"<center><h1>511 Network Authentication Required</h1></center>" CRLF
+"<p>You need to "
+"authenticate with the local network in order to gain access."
+;
+
+
static ngx_str_t ngx_http_error_pages[] = {

ngx_null_string, /* 201, 204 */
@@ -334,11 +352,25 @@
ngx_string(ngx_http_error_414_page),
ngx_string(ngx_http_error_415_page),
ngx_string(ngx_http_error_416_page),
+ ngx_null_string, /* 417 */
+ ngx_null_string, /* 418 */
+ ngx_null_string, /* 419 */
+ ngx_null_string, /* 420 */
+ ngx_null_string, /* 421 */
+ ngx_null_string, /* 422 */
+ ngx_null_string, /* 423 */
+ ngx_null_string, /* 424 */
+ ngx_null_string, /* 425 */
+ ngx_null_string, /* 426 */
+ ngx_null_string, /* 427 */
+ ngx_null_string, /* 428 */
+ ngx_string(ngx_http_error_429_page),
+ ngx_null_string, /* 430 */
+ ngx_string(ngx_http_error_431_page),

-#define NGX_HTTP_LAST_4XX 417
+#define NGX_HTTP_LAST_4XX 432
#define NGX_HTTP_OFF_5XX (NGX_HTTP_LAST_4XX - 400 + NGX_HTTP_OFF_4XX)

- ngx_string(ngx_http_error_494_page), /* 494, request header too large
*/
ngx_string(ngx_http_error_495_page), /* 495, https certificate error */
ngx_string(ngx_http_error_496_page), /* 496, https no certificate */
ngx_string(ngx_http_error_497_page), /* 497, http to https */
@@ -352,9 +384,13 @@
ngx_string(ngx_http_error_504_page),
ngx_null_string, /* 505 */
ngx_null_string, /* 506 */
- ngx_string(ngx_http_error_507_page)
+ ngx_string(ngx_http_error_507_page),
+ ngx_null_string, /* 508 */
+ ngx_null_string, /* 509 */
+ ngx_null_string, /* 510 */
+ ngx_string(ngx_http_error_511_page),

-#define NGX_HTTP_LAST_5XX 508
+#define NGX_HTTP_LAST_5XX 512

};

@@ -460,7 +496,6 @@
case NGX_HTTP_TO_HTTPS:
case NGX_HTTPS_CERT_ERROR:
case NGX_HTTPS_NO_CERT:
- case NGX_HTTP_REQUEST_HEADER_TOO_LARGE:
r->err_status = NGX_HTTP_BAD_REQUEST;
break;
}
Index: src/http/modules/ngx_http_limit_req_module.c
===================================================================
--- src/http/modules/ngx_http_limit_req_module.c (revision 4615)
+++ src/http/modules/ngx_http_limit_req_module.c (working copy)
@@ -245,7 +245,7 @@
ctx->node = NULL;
}

- return NGX_HTTP_SERVICE_UNAVAILABLE;
+ return NGX_HTTP_TOO_MANY_REQUESTS;
}

/* rc == NGX_AGAIN || rc == NGX_OK */
Index: src/http/ngx_http_request.h
===================================================================
--- src/http/ngx_http_request.h (revision 4615)
+++ src/http/ngx_http_request.h (working copy)
@@ -91,16 +91,18 @@
#define NGX_HTTP_UNSUPPORTED_MEDIA_TYPE 415
#define NGX_HTTP_RANGE_NOT_SATISFIABLE 416

+/* RFC 6585 */
+#define NGX_HTTP_TOO_MANY_REQUESTS 429
+#define NGX_HTTP_REQUEST_HEADER_TOO_LARGE 431

+
/* Our own HTTP codes */

/* The special code to close connection without any response */
#define NGX_HTTP_CLOSE 444

-#define NGX_HTTP_NGINX_CODES 494
+#define NGX_HTTP_NGINX_CODES 495

-#define NGX_HTTP_REQUEST_HEADER_TOO_LARGE 494
-
#define NGX_HTTPS_CERT_ERROR 495
#define NGX_HTTPS_NO_CERT 496

@@ -128,7 +130,10 @@
#define NGX_HTTP_GATEWAY_TIME_OUT 504
#define NGX_HTTP_INSUFFICIENT_STORAGE 507

+/* RFC 6585 */
+#define NGX_HTTP_NETWORK_AUTHENTICATION_REQUIRED 511

+
#define NGX_HTTP_LOWLEVEL_BUFFERED 0xf0
#define NGX_HTTP_WRITE_BUFFERED 0x10
#define NGX_HTTP_GZIP_BUFFERED 0x20
Index: src/http/ngx_http_header_filter_module.c
===================================================================
--- src/http/ngx_http_header_filter_module.c (revision 4615)
+++ src/http/ngx_http_header_filter_module.c (working copy)
@@ -99,16 +99,24 @@
ngx_string("415 Unsupported Media Type"),
ngx_string("416 Requested Range Not Satisfiable"),

- /* ngx_null_string, */ /* "417 Expectation Failed" */
- /* ngx_null_string, */ /* "418 unused" */
- /* ngx_null_string, */ /* "419 unused" */
- /* ngx_null_string, */ /* "420 unused" */
- /* ngx_null_string, */ /* "421 unused" */
- /* ngx_null_string, */ /* "422 Unprocessable Entity" */
- /* ngx_null_string, */ /* "423 Locked" */
- /* ngx_null_string, */ /* "424 Failed Dependency" */
+ ngx_null_string, /* "417 Expectation Failed" */
+ ngx_null_string, /* "418 unused" */
+ ngx_null_string, /* "419 unused" */
+ ngx_null_string, /* "420 unused" */
+ ngx_null_string, /* "421 unused" */
+ ngx_null_string, /* "422 Unprocessable Entity" */
+ ngx_null_string, /* "423 Locked" */
+ ngx_null_string, /* "424 Failed Dependency" */
+ ngx_null_string, /* "425 unused" */
+ ngx_null_string, /* "426 unused" */
+ ngx_null_string, /* "427 unused" */
+ ngx_null_string, /* "428 Precondition Required" */

-#define NGX_HTTP_LAST_4XX 417
+ ngx_string("429 Too Many Requests"),
+ ngx_null_string, /* "430 unused" */
+ ngx_string("431 Request Header Fields Too Large"),
+
+#define NGX_HTTP_LAST_4XX 432
#define NGX_HTTP_OFF_5XX (NGX_HTTP_LAST_4XX - 400 + NGX_HTTP_OFF_4XX)

ngx_string("500 Internal Server Error"),
@@ -120,12 +128,14 @@
ngx_null_string, /* "505 HTTP Version Not Supported" */
ngx_null_string, /* "506 Variant Also Negotiates" */
ngx_string("507 Insufficient Storage"),
- /* ngx_null_string, */ /* "508 unused" */
- /* ngx_null_string, */ /* "509 unused" */
- /* ngx_null_string, */ /* "510 Not Extended" */
+ ngx_null_string, /* "508 unused" */
+ ngx_null_string, /* "509 unused" */
+ ngx_null_string, /* "510 Not Extended" */

-#define NGX_HTTP_LAST_5XX 508
+ ngx_string("511 Network Authentication Required"),

+#define NGX_HTTP_LAST_5XX 512
+
};





--
do not fear to be eccentric in opinion, for every opinion now accepted was
once eccentric.
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH]add new http status code Attachments

Simon Liu 2345 May 08, 2012 08:12AM

Re: [PATCH]add new http status code

Maxim Dounin 621 May 08, 2012 03:40PM

Re: [PATCH]add new http status code

Manlio Perillo 705 May 08, 2012 05:26PM

Re: [PATCH]add new http status code

Maxim Dounin 535 May 09, 2012 07:08AM

Re: [PATCH]add new http status code

Simon Liu 612 May 09, 2012 08:00AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 301
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready