Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2016-05-20 18:41:17 +0300
committerValentin Bartenev <vbart@nginx.com>2016-05-20 18:41:17 +0300
commitf0c3ae9fc37b21e42b9430554391b17b79a70000 (patch)
tree7935dd308f10ef4de0ff1ca697883881334c6bee
parent955f741af0d77f4fc51a312913f81a15af240d26 (diff)
HTTP/2: the "421 Misdirected Request" response (closes #848).
Since 4fbef397c753 nginx rejects with the 400 error any attempts of requesting different host over the same connection, if the relevant virtual server requires verification of a client certificate. While requesting hosts other than negotiated isn't something legal in HTTP/1.x, the HTTP/2 specification explicitly permits such requests for connection reuse and has introduced a special response code 421. According to RFC 7540 Section 9.1.2 this code can be sent by a server that is not configured to produce responses for the combination of scheme and authority that are included in the request URI. And the client may retry the request over a different connection. Now this code is used for requests that aren't authorized in current connection. After receiving the 421 response a client will be able to open a new connection, provide the required certificate and retry the request. Unfortunately, not all clients currently are able to handle it well. Notably Chrome just shows an error, while at least the latest version of Firefox retries the request over a new connection.
-rw-r--r--src/http/ngx_http_header_filter_module.c14
-rw-r--r--src/http/ngx_http_request.c2
-rw-r--r--src/http/ngx_http_request.h1
-rw-r--r--src/http/ngx_http_special_response.c15
4 files changed, 23 insertions, 9 deletions
diff --git a/src/http/ngx_http_header_filter_module.c b/src/http/ngx_http_header_filter_module.c
index 507dc939c..2cf1205f9 100644
--- a/src/http/ngx_http_header_filter_module.c
+++ b/src/http/ngx_http_header_filter_module.c
@@ -95,17 +95,17 @@ static ngx_str_t ngx_http_status_lines[] = {
ngx_string("414 Request-URI Too Large"),
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_string("421 Misdirected Request"),
- /* 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" */
-#define NGX_HTTP_LAST_4XX 417
+#define NGX_HTTP_LAST_4XX 422
#define NGX_HTTP_OFF_5XX (NGX_HTTP_LAST_4XX - 400 + NGX_HTTP_OFF_4XX)
ngx_string("500 Internal Server Error"),
@@ -113,10 +113,10 @@ static ngx_str_t ngx_http_status_lines[] = {
ngx_string("502 Bad Gateway"),
ngx_string("503 Service Temporarily Unavailable"),
ngx_string("504 Gateway Time-out"),
-
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" */
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 7d6cada4d..c2ce2224f 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -2065,7 +2065,7 @@ ngx_http_set_virtual_server(ngx_http_request_t *r, ngx_str_t *host)
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
"client attempted to request the server name "
"different from that one was negotiated");
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
+ ngx_http_finalize_request(r, NGX_HTTP_MISDIRECTED_REQUEST);
return NGX_ERROR;
}
}
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index cfde7dc7e..57f8583dd 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -95,6 +95,7 @@
#define NGX_HTTP_REQUEST_URI_TOO_LARGE 414
#define NGX_HTTP_UNSUPPORTED_MEDIA_TYPE 415
#define NGX_HTTP_RANGE_NOT_SATISFIABLE 416
+#define NGX_HTTP_MISDIRECTED_REQUEST 421
/* Our own HTTP codes */
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index 2771e588c..64e5acd55 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -210,6 +210,14 @@ static char ngx_http_error_416_page[] =
;
+static char ngx_http_error_421_page[] =
+"<html>" CRLF
+"<head><title>421 Misdirected Request</title></head>" CRLF
+"<body bgcolor=\"white\">" CRLF
+"<center><h1>421 Misdirected Request</h1></center>" CRLF
+;
+
+
static char ngx_http_error_494_page[] =
"<html>" CRLF
"<head><title>400 Request Header Or Cookie Too Large</title></head>"
@@ -334,8 +342,13 @@ static ngx_str_t ngx_http_error_pages[] = {
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_string(ngx_http_error_421_page),
-#define NGX_HTTP_LAST_4XX 417
+#define NGX_HTTP_LAST_4XX 422
#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 */