Skip to content

Commit

Permalink
Make mod_zip compatible with nginx 1.23.0+ (#93)
Browse files Browse the repository at this point in the history
nginx 1.23 changed the way known multi value headers are handled (as linked lists)
  • Loading branch information
d--j committed Jun 25, 2022
1 parent 808fb55 commit 5b2604b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
fail-fast: false
matrix:
compiler: [ gcc, clang ]
version: [ 1.19.10, 1.20.2, 1.21.4 ]
version: [ 1.19.10, 1.20.2, 1.21.4, 1.22.0, 1.23.0 ]
steps:
- name: Install carton
run: sudo apt install carton
Expand Down
12 changes: 12 additions & 0 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@ if [ $ngx_found = yes ]; then
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
ngx_found=no
fi

ngx_feature="multi-value headers are linked lists (nginx 1.23.0+)"
ngx_feature_name="NGX_ZIP_MULTI_HEADERS_LINKED_LISTS"
ngx_feature_run=yes
ngx_feature_incs="#include \"nginx.h\""
ngx_feature_path="src/core"
ngx_feature_test="
#if nginx_version < 1023000
#error multi headers are no linked lists
#endif
"
. auto/feature
7 changes: 4 additions & 3 deletions ngx_http_zip_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ngx_http_zip_file.h"
#include "ngx_http_zip_file_format.h"
#include "ngx_http_zip_endian.h"
#include "ngx_http_zip_headers.h"

#ifdef NGX_ZIP_HAVE_ICONV
#include <iconv.h>
Expand Down Expand Up @@ -252,7 +253,7 @@ ngx_http_zip_generate_pieces(ngx_http_request_t *r, ngx_http_zip_ctx_t *ctx)
// because UFT-8 flag (zip_utf8_flag) is set default for templates.
ngx_int_t variable_header_status = NGX_OK;
if (r->upstream) {
variable_header_status = ngx_http_variable_unknown_header(vv, &ngx_http_zip_header_name_separator,
variable_header_status = ngx_http_zip_variable_unknown_header(r, vv, &ngx_http_zip_header_name_separator,
&r->upstream->headers_in.headers.part, sizeof("upstream_http_")-1);
} else {
vv->not_found = 1;
Expand All @@ -266,7 +267,7 @@ ngx_http_zip_generate_pieces(ngx_http_request_t *r, ngx_http_zip_ctx_t *ctx)
#ifdef NGX_ZIP_HAVE_ICONV
variable_header_status = NGX_OK;
if (r->upstream) {
variable_header_status = ngx_http_variable_unknown_header(vv, &ngx_http_zip_header_charset_name,
variable_header_status = ngx_http_zip_variable_unknown_header(r, vv, &ngx_http_zip_header_charset_name,
&r->upstream->headers_in.headers.part, sizeof("upstream_http_")-1);
} else {
vv->not_found = 1;
Expand Down Expand Up @@ -431,7 +432,7 @@ ngx_http_zip_generate_pieces(ngx_http_request_t *r, ngx_http_zip_ctx_t *ctx)

// Collect names of original request's header fields that
// have to be present in each of the issued sub-requests.
variable_header_status = ngx_http_variable_unknown_header(vv, &ngx_http_zip_header_name_pass_headers,
variable_header_status = ngx_http_zip_variable_unknown_header(r, vv, &ngx_http_zip_header_name_pass_headers,
&r->upstream->headers_in.headers.part, sizeof("upstream_http_")-1);

if (variable_header_status == NGX_OK && !vv->not_found) {
Expand Down
44 changes: 44 additions & 0 deletions ngx_http_zip_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,36 @@ ngx_http_zip_find_key_in_set(ngx_str_t *key, ngx_array_t *set)
ngx_int_t
ngx_http_zip_add_cache_control(ngx_http_request_t *r)
{
#ifdef NGX_ZIP_MULTI_HEADERS_LINKED_LISTS
ngx_table_elt_t *cc;

/* convoluted way of adding Cache-Control: max-age=0 */
/* The header is necessary so IE doesn't barf */
cc = r->headers_out.cache_control;

if (cc == NULL) {
cc = ngx_list_push(&r->headers_out.headers);
if (cc == NULL) {
return NGX_ERROR;
}

r->headers_out.cache_control = cc;
cc->next = NULL;
cc->hash = 1;
ngx_str_set(&cc->key, "Cache-Control");
} else {
for (cc = cc->next; cc; cc = cc->next) {
cc->hash = 0;
}

cc = r->headers_out.cache_control;
cc->next = NULL;
}

ngx_str_set(&cc->value, "max-age=0");

return NGX_OK;
#else
ngx_table_elt_t **ccp, *cc;
ngx_uint_t i;

Expand Down Expand Up @@ -62,6 +92,7 @@ ngx_http_zip_add_cache_control(ngx_http_request_t *r)
ngx_str_set(&cc->value, "max-age=0");

return NGX_OK;
#endif
}

ngx_int_t
Expand Down Expand Up @@ -285,3 +316,16 @@ ngx_http_zip_init_subrequest_headers(ngx_http_request_t *r, ngx_http_zip_ctx_t *

return NGX_OK;
}


ngx_int_t
ngx_http_zip_variable_unknown_header(ngx_http_request_t *r,
ngx_http_variable_value_t *v, ngx_str_t *var,
ngx_list_part_t *part, size_t prefix)
{
#ifdef NGX_ZIP_MULTI_HEADERS_LINKED_LISTS
return ngx_http_variable_unknown_header(r, v, var, part, prefix);
#else
return ngx_http_variable_unknown_header(v, var, part, prefix);
#endif
}
4 changes: 4 additions & 0 deletions ngx_http_zip_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ ngx_int_t ngx_http_zip_init_multipart_range(ngx_http_request_t *r,
ngx_int_t ngx_http_zip_init_subrequest_headers(ngx_http_request_t *r, ngx_http_zip_ctx_t *ctx,
ngx_http_request_t *sr, ngx_http_zip_range_t *piece_range,
ngx_http_zip_range_t *req_range);

ngx_int_t ngx_http_zip_variable_unknown_header(ngx_http_request_t *r,
ngx_http_variable_value_t *v, ngx_str_t *var, ngx_list_part_t *part,
size_t prefix);
8 changes: 4 additions & 4 deletions ngx_http_zip_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ ngx_http_zip_main_request_header_filter(ngx_http_request_t *r)
/* Look for X-Archive-Files */
ngx_int_t variable_header_status = NGX_OK;
if (r->upstream) {
variable_header_status = ngx_http_variable_unknown_header(vv,
variable_header_status = ngx_http_zip_variable_unknown_header(r, vv,
&ngx_http_zip_header_variable_name,
&r->upstream->headers_in.headers.part, sizeof("upstream_http_") - 1);
&r->upstream->headers_in.headers.part, sizeof("upstream_http_") - 1);
} else if (r->headers_out.status == NGX_HTTP_OK) {
variable_header_status = ngx_http_variable_unknown_header(vv,
variable_header_status = ngx_http_zip_variable_unknown_header(r, vv,
&ngx_http_zip_header_variable_name,
&r->headers_out.headers.part, sizeof("upstream_http_") - 1);
&r->headers_out.headers.part, sizeof("upstream_http_") - 1);
} else {
vv->not_found = 1;
}
Expand Down

0 comments on commit 5b2604b

Please sign in to comment.