[PATCH]add new http status code

Simon Liu simohayha.bobo at gmail.com
Tue May 8 12:10:46 UTC 2012


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20120508/cb261275/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginx_trunk_rfc6585.patch
Type: application/octet-stream
Size: 7465 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20120508/cb261275/attachment-0001.obj>


More information about the nginx-devel mailing list