[PATCH 1 of 4] HTTP/2: reject HTTP/2 requests with "Connection" header
Piotr Sikora
piotrsikora at google.com
Tue Jun 13 12:19:45 UTC 2017
# HG changeset patch
# User Piotr Sikora <piotrsikora at google.com>
# Date 1490516709 25200
# Sun Mar 26 01:25:09 2017 -0700
# Node ID 10c3f4c37f96ef496eff859b6f6815817e79455a
# Parent e6f399a176e7cae0fa08f1183d31315bce3b9ecb
HTTP/2: reject HTTP/2 requests with "Connection" header.
While there, populate r->headers_in.connection.
Signed-off-by: Piotr Sikora <piotrsikora at google.com>
diff -r e6f399a176e7 -r 10c3f4c37f96 src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -1678,6 +1678,22 @@ static ngx_int_t
ngx_http_process_connection(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
{
+ if (r->headers_in.connection == NULL) {
+ r->headers_in.connection = h;
+ }
+
+#if (NGX_HTTP_V2)
+
+ if (r->stream) {
+ ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+ "client sent HTTP/2 request with \"Connection\" header");
+
+ ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
+ return NGX_ERROR;
+ }
+
+#endif
+
if (ngx_strcasestrn(h->value.data, "close", 5 - 1)) {
r->headers_in.connection_type = NGX_HTTP_CONNECTION_CLOSE;
More information about the nginx-devel
mailing list