mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Squashed 'src/deps/src/headers-more-nginx-module/' changes from bea1be3bbf..06dc0be56e
06dc0be56e tests: suppress stderr for use cases with conf parsing errors. (#158) c74748ab3f bugfix: fixed uninitialised field 'h[i]->append'. (#157) 3fb97bcf57 tests: update nginx to 1.25.3. db45361256 bugfix: remove the Set-Cookie restriction of `-a` option. 53b135c9d9 optimize: set r->keepalive 0 to close connection. e569137eb9 feature: add append mode for more_set_headers(so far just for Set-Cookie field). 607d1b1f32 feature: upgrade nginx to 1.25.1. 010e5b4215 bugfix: fixed an unused variable on non-debug builds. 33b646d69f doc: update the release version and date in README.md. git-subtree-dir: src/deps/src/headers-more-nginx-module git-subtree-split: 06dc0be56e5ec9f7fd814e881b066b5540a85bec
This commit is contained in:
parent
c7f7669a8c
commit
c2f7142a5a
6 changed files with 147 additions and 18 deletions
11
.travis.yml
11
.travis.yml
|
|
@ -1,5 +1,9 @@
|
|||
sudo: required
|
||||
dist: bionic
|
||||
dist: focal
|
||||
|
||||
branches:
|
||||
only:
|
||||
- "master"
|
||||
|
||||
os: linux
|
||||
|
||||
|
|
@ -21,9 +25,8 @@ env:
|
|||
- LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
|
||||
- LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
|
||||
matrix:
|
||||
- NGINX_VERSION=1.19.3
|
||||
- NGINX_VERSION=1.19.9
|
||||
- NGINX_VERSION=1.23.0 WITHOUT_PCRE2=1
|
||||
- NGINX_VERSION=1.21.4
|
||||
- NGINX_VERSION=1.25.3 WITHOUT_PCRE2=1
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update -y
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ Table of Contents
|
|||
Version
|
||||
=======
|
||||
|
||||
This document describes headers-more-nginx-module [v0.33](https://github.com/openresty/headers-more-nginx-module/tags) released on 3 November 2017.
|
||||
This document describes headers-more-nginx-module [v0.34](https://github.com/openresty/headers-more-nginx-module/tags) released on 17 July 2022.
|
||||
|
||||
Synopsis
|
||||
========
|
||||
|
|
@ -134,7 +134,7 @@ Directives
|
|||
|
||||
more_set_headers
|
||||
----------------
|
||||
**syntax:** *more_set_headers [-t <content-type list>]... [-s <status-code list>]... <new-header>...*
|
||||
**syntax:** *more_set_headers [-t <content-type list>]... [-s <status-code list>]... [-a] <new-header>...*
|
||||
|
||||
**default:** *no*
|
||||
|
||||
|
|
@ -144,6 +144,8 @@ more_set_headers
|
|||
|
||||
Replaces (if any) or adds (if not any) the specified output headers when the response status code matches the codes specified by the `-s` option *AND* the response content type matches the types specified by the `-t` option.
|
||||
|
||||
If the "-a" option is specified, the specified output headers can be appended directly without clearing the old fields. The behavior of builtin headers such as "Content-Type", "Content-Length", "Server", etc. cannot be changed.
|
||||
|
||||
If either `-s` or `-t` is not specified or has an empty list value, then no match is required. Therefore, the following directive set the `Server` output header to the custom value for *any* status code and *any* content type:
|
||||
|
||||
```nginx
|
||||
|
|
|
|||
|
|
@ -60,8 +60,9 @@ struct ngx_http_headers_more_header_val_s {
|
|||
ngx_str_t key;
|
||||
ngx_http_headers_more_set_header_pt handler;
|
||||
ngx_uint_t offset;
|
||||
ngx_flag_t replace;
|
||||
ngx_flag_t wildcard;
|
||||
unsigned replace:1;
|
||||
unsigned wildcard:1;
|
||||
unsigned append:1;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -748,6 +748,7 @@ ngx_http_set_connection_header(ngx_http_request_t *r,
|
|||
if (ngx_strcasestrn(value->data, "close", 5 - 1)) {
|
||||
r->headers_in.connection_type = NGX_HTTP_CONNECTION_CLOSE;
|
||||
r->headers_in.keep_alive_n = -1;
|
||||
r->keepalive = 0;
|
||||
|
||||
} else if (ngx_strcasestrn(value->data, "keep-alive", 10 - 1)) {
|
||||
r->headers_in.connection_type = NGX_HTTP_CONNECTION_KEEP_ALIVE;
|
||||
|
|
@ -763,7 +764,9 @@ ngx_http_set_builtin_multi_header(ngx_http_request_t *r,
|
|||
{
|
||||
#if defined(nginx_version) && nginx_version >= 1023000
|
||||
ngx_table_elt_t **headers, **ph, *h;
|
||||
#if (DDEBUG)
|
||||
int nelts;
|
||||
#endif
|
||||
|
||||
if (r->headers_out.status == 400 || r->headers_in.headers.last == NULL) {
|
||||
/* must be a 400 Bad Request */
|
||||
|
|
@ -773,14 +776,16 @@ ngx_http_set_builtin_multi_header(ngx_http_request_t *r,
|
|||
headers = (ngx_table_elt_t **) ((char *) &r->headers_in + hv->offset);
|
||||
|
||||
if (*headers) {
|
||||
#if (DDEBUG)
|
||||
nelts = 0;
|
||||
for (h = *headers; h; h = h->next) {
|
||||
nelts++;
|
||||
}
|
||||
|
||||
*headers = NULL;
|
||||
|
||||
dd("clear multi-value headers: %d", nelts);
|
||||
#endif
|
||||
|
||||
*headers = NULL;
|
||||
}
|
||||
|
||||
if (ngx_http_set_header_helper(r, hv, value, &h) == NGX_ERROR) {
|
||||
|
|
|
|||
|
|
@ -184,6 +184,10 @@ ngx_http_set_header_helper(ngx_http_request_t *r,
|
|||
}
|
||||
#endif
|
||||
|
||||
if (hv->append) {
|
||||
goto append;
|
||||
}
|
||||
|
||||
part = &r->headers_out.headers.part;
|
||||
h = part->elts;
|
||||
|
||||
|
|
@ -255,6 +259,8 @@ matched:
|
|||
* is empty because some builtin headers like Last-Modified
|
||||
* relies on this to get cleared */
|
||||
|
||||
append:
|
||||
|
||||
h = ngx_list_push(&r->headers_out.headers);
|
||||
if (h == NULL) {
|
||||
return NGX_ERROR;
|
||||
|
|
@ -606,14 +612,18 @@ static char *
|
|||
ngx_http_headers_more_parse_directive(ngx_conf_t *cf, ngx_command_t *ngx_cmd,
|
||||
void *conf, ngx_http_headers_more_opcode_t opcode)
|
||||
{
|
||||
ngx_http_headers_more_loc_conf_t *hlcf = conf;
|
||||
ngx_http_headers_more_loc_conf_t *hlcf = conf;
|
||||
|
||||
ngx_uint_t i;
|
||||
ngx_http_headers_more_cmd_t *cmd;
|
||||
ngx_str_t *arg;
|
||||
ngx_flag_t ignore_next_arg;
|
||||
ngx_str_t *cmd_name;
|
||||
ngx_int_t rc;
|
||||
ngx_uint_t i, j;
|
||||
ngx_http_headers_more_cmd_t *cmd;
|
||||
ngx_str_t *arg;
|
||||
ngx_flag_t ignore_next_arg;
|
||||
ngx_str_t *cmd_name;
|
||||
ngx_int_t rc;
|
||||
ngx_flag_t append = 0;
|
||||
ngx_flag_t is_builtin_header = 0;
|
||||
ngx_http_headers_more_header_val_t *h;
|
||||
ngx_http_headers_more_set_header_t *handlers;
|
||||
|
||||
ngx_http_headers_more_main_conf_t *hmcf;
|
||||
|
||||
|
|
@ -721,6 +731,22 @@ ngx_http_headers_more_parse_directive(ngx_conf_t *cf, ngx_command_t *ngx_cmd,
|
|||
ignore_next_arg = 1;
|
||||
|
||||
continue;
|
||||
|
||||
} else if (arg[i].data[1] == 'a') {
|
||||
|
||||
if (ngx_strncasecmp((u_char *) "more_set_headers",
|
||||
cmd_name->data, cmd_name->len) != 0)
|
||||
{
|
||||
ngx_log_error(NGX_LOG_ERR, cf->log, 0,
|
||||
"%V: invalid option name: \"%V\"",
|
||||
cmd_name, &arg[i]);
|
||||
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
dd("Found append flag");
|
||||
append = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -736,6 +762,37 @@ ngx_http_headers_more_parse_directive(ngx_conf_t *cf, ngx_command_t *ngx_cmd,
|
|||
|
||||
if (cmd->headers->nelts == 0) {
|
||||
cmd->headers = NULL;
|
||||
|
||||
} else {
|
||||
|
||||
h = cmd->headers->elts;
|
||||
for (i = 0; i < cmd->headers->nelts; i++) {
|
||||
h[i].append = 0;
|
||||
|
||||
handlers = ngx_http_headers_more_set_handlers;
|
||||
|
||||
for (j = 0; handlers[j].name.len; j++) {
|
||||
if (h[i].key.len == handlers[j].name.len
|
||||
&& ngx_strncasecmp(h[i].key.data, handlers[j].name.data,
|
||||
h[i].key.len) == 0)
|
||||
{
|
||||
is_builtin_header = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_builtin_header && append) {
|
||||
ngx_log_error(NGX_LOG_ERR, cf->log, 0,
|
||||
"%V: can not append builtin headers \"%V\"",
|
||||
cmd_name, &h[i].key);
|
||||
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (!is_builtin_header) {
|
||||
h[i].append = append;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd->types->nelts == 0) {
|
||||
|
|
|
|||
63
t/sanity.t
63
t/sanity.t
|
|
@ -5,7 +5,7 @@ use Test::Nginx::Socket;
|
|||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * 113;
|
||||
plan tests => repeat_each() * 123;
|
||||
|
||||
#master_on();
|
||||
#workers(2);
|
||||
|
|
@ -565,3 +565,64 @@ hi
|
|||
--- response_body
|
||||
ok
|
||||
--- http09
|
||||
|
||||
|
||||
|
||||
=== TEST 34: use the -a option to append the cookie field
|
||||
--- config
|
||||
location /cookie {
|
||||
more_set_headers -a 'Set-Cookie: name=lynch';
|
||||
echo ok;
|
||||
}
|
||||
--- request
|
||||
GET /cookie
|
||||
--- response_headers
|
||||
Set-Cookie: name=lynch
|
||||
--- response_body
|
||||
ok
|
||||
|
||||
|
||||
|
||||
=== TEST 35: the original Set-Cookie fields will not be overwritten, when using the -a option
|
||||
--- config
|
||||
location /cookie {
|
||||
more_set_headers 'Set-Cookie: name=lynch';
|
||||
more_set_headers -a 'Set-Cookie: born=1981';
|
||||
echo ok;
|
||||
}
|
||||
--- request
|
||||
GET /cookie
|
||||
--- raw_response_headers_like eval
|
||||
"Set-Cookie: name=lynch\r\nSet-Cookie: born=1981\r\n"
|
||||
--- response_body
|
||||
ok
|
||||
|
||||
|
||||
|
||||
=== TEST 36: The behavior of builtin headers can not be changed
|
||||
--- config
|
||||
location /foo {
|
||||
more_set_headers -a "Server: myServer";
|
||||
echo ok;
|
||||
}
|
||||
--- request
|
||||
GET /foo
|
||||
--- must_die
|
||||
--- error_log chomp
|
||||
can not append builtin headers
|
||||
--- suppress_stderr
|
||||
|
||||
|
||||
|
||||
=== TEST 37: can not use -a option with more_clear_headers
|
||||
--- config
|
||||
location /foo {
|
||||
more_clear_headers -a 'Content-Type';
|
||||
echo ok;
|
||||
}
|
||||
--- request
|
||||
GET /foo
|
||||
--- must_die
|
||||
--- error_log chomp
|
||||
invalid option name: "-a"
|
||||
--- suppress_stderr
|
||||
|
|
|
|||
Loading…
Reference in a new issue