diff --git a/README b/README index f57defb..6957ce7 100644 --- a/README +++ b/README @@ -17,7 +17,8 @@ If-Unmodified-Since, If-Modified-Since, Date, Accept-Encoding, Accept-Language, Accept-Charset, Max-Forwards, If-Match, If-None-Match, Last-Modified, Content-Length, Expires, - Content-Language, Content-Encoding, Allow, Host, Accept + Content-Language, Content-Encoding, Allow, Host, Accept, + Connection Report Bugs Create a ticket on the issue tracking interface of GitHub: diff --git a/ngx_http_header_inspect.c b/ngx_http_header_inspect.c index 4ce71ad..ab2ca30 100644 --- a/ngx_http_header_inspect.c +++ b/ngx_http_header_inspect.c @@ -37,6 +37,7 @@ static ngx_int_t ngx_header_inspect_allow_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); static ngx_int_t ngx_header_inspect_host_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); static ngx_int_t ngx_header_inspect_accept_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); +static ngx_int_t ngx_header_inspect_connection_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); static ngx_int_t ngx_header_inspect_ifrange_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); static ngx_int_t ngx_header_inspect_date_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, char *header, ngx_str_t value); static ngx_int_t ngx_header_inspect_process_request(ngx_http_request_t *r); @@ -1360,6 +1361,20 @@ return rc; } +static ngx_int_t ngx_header_inspect_connection_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value) { + /* TODO: check with RFC for allowed header values */ + if ( (value.len == 5) && (ngx_strcmp("close", value.data) == 0) ) { + return NGX_OK; + } else if ( (value.len == 10) && (ngx_strcmp("keep-alive", value.data) == 0) ) { + return NGX_OK; + } else { + if ( conf->log ) { + ngx_log_error(NGX_LOG_ALERT, log, 0, "header_inspect: illegal value in Connection header \"%s\"", value.data); + } + return NGX_ERROR; + } +} + static ngx_int_t ngx_header_inspect_accept_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value) { ngx_int_t rc = NGX_AGAIN; ngx_uint_t i = 0; @@ -1726,6 +1741,11 @@ if ((rc != NGX_OK) && conf->block) { return NGX_HTTP_BAD_REQUEST; } + } else if ((h[i].key.len == 10) && (ngx_strcmp("Connection", h[i].key.data) == 0) ) { + rc = ngx_header_inspect_connection_header(conf, r->connection->log, h[i].value); + if ((rc != NGX_OK) && conf->block) { + return NGX_HTTP_BAD_REQUEST; + } } else { /* TODO: support for other headers */ if (conf->log_uninspected) {