HTTP/2: reject HTTP/2 requests with "Connection" header. While there, populate r->headers_in.connection. Change-Id: Icfe42f019081d254c0a4a157d829e39cf9ddc875 Signed-off-by: Piotr Sikora <piotrsikora@google.com> Reviewed-on: https://nginx-review.googlesource.com/2827 Reviewed-by: Lizan Zhou <zlizan@google.com>
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index d1012ad..a9a9206 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c
@@ -1673,6 +1673,22 @@ 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->http_version >= NGX_HTTP_VERSION_20) { + 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;