Merge commit 'c2f7142a5a4a0f57460f439d03b8b286aaf48001' into dev

This commit is contained in:
Théophile Diot 2025-01-17 10:29:09 +01:00
commit b2a73f944e
No known key found for this signature in database
GPG key ID: FA995104A0BA376A
5 changed files with 85 additions and 17 deletions

View file

@ -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

View file

@ -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

View file

@ -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;
};

View file

@ -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) {

View file

@ -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) {