[nginx] HTTP/2: the "421 Misdirected Request" response (closes #848).
Valentin Bartenev
vbart at nginx.com
Fri May 20 15:46:08 UTC 2016
details: http://hg.nginx.org/nginx/rev/654d2dae97d3
branches:
changeset: 6556:654d2dae97d3
user: Valentin Bartenev <vbart at nginx.com>
date: Fri May 20 18:41:17 2016 +0300
description:
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.
diffstat:
src/http/ngx_http_header_filter_module.c | 14 +++++++-------
src/http/ngx_http_request.c | 2 +-
src/http/ngx_http_request.h | 1 +
src/http/ngx_http_special_response.c | 15 ++++++++++++++-
4 files changed, 23 insertions(+), 9 deletions(-)
diffs (95 lines):
diff -r 090a78da4f88 -r 654d2dae97d3 src/http/ngx_http_header_filter_module.c
--- a/src/http/ngx_http_header_filter_module.c Fri May 20 17:02:04 2016 +0300
+++ b/src/http/ngx_http_header_filter_module.c Fri May 20 18:41:17 2016 +0300
@@ -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 -r 090a78da4f88 -r 654d2dae97d3 src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c Fri May 20 17:02:04 2016 +0300
+++ b/src/http/ngx_http_request.c Fri May 20 18:41:17 2016 +0300
@@ -2069,7 +2069,7 @@ ngx_http_set_virtual_server(ngx_http_req
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 -r 090a78da4f88 -r 654d2dae97d3 src/http/ngx_http_request.h
--- a/src/http/ngx_http_request.h Fri May 20 17:02:04 2016 +0300
+++ b/src/http/ngx_http_request.h Fri May 20 18:41:17 2016 +0300
@@ -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 -r 090a78da4f88 -r 654d2dae97d3 src/http/ngx_http_special_response.c
--- a/src/http/ngx_http_special_response.c Fri May 20 17:02:04 2016 +0300
+++ b/src/http/ngx_http_special_response.c Fri May 20 18:41:17 2016 +0300
@@ -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 */
More information about the nginx-devel
mailing list