Skip to content

Commit

Permalink
Preserve some important headers in subrequests
Browse files Browse the repository at this point in the history
  • Loading branch information
devgs committed Nov 17, 2021
1 parent b324072 commit f531c55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions ngx_http_zip_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ ngx_int_t
ngx_http_zip_init_subrequest_headers(ngx_http_request_t *r, ngx_http_request_t *sr,
ngx_http_zip_range_t *piece_range, ngx_http_zip_range_t *req_range)
{
ngx_list_t headers_old;
ngx_list_part_t *next_part;
ngx_table_elt_t *h;
ngx_uint_t i;

ngx_memcpy(&headers_old, &sr->headers_in.headers, sizeof(headers_old));
ngx_memzero(&sr->headers_in, sizeof(sr->headers_in));
sr->headers_in.content_length_n = -1;
sr->headers_in.keep_alive_n = -1;
Expand All @@ -217,6 +223,23 @@ ngx_http_zip_init_subrequest_headers(ngx_http_request_t *r, ngx_http_request_t *
return NGX_ERROR;
}

next_part = &headers_old.part;

for (; next_part; next_part = next_part->next) {
h = next_part->elts;

for (i = 0; i < next_part->nelts; ++i) {
if ((!ngx_rstrncasecmp(h[i].key.data, "X-", sizeof("X-") - 1)
&& ngx_rstrncasecmp(h[i].key.data, "X-Range", sizeof("X-Range") - 1))
|| !ngx_rstrncasecmp(h[i].key.data, "Authorization", sizeof("Authorization") - 1)
|| !ngx_rstrncasecmp(h[i].key.data, "Cookie", sizeof("Cookie") - 1)
|| !ngx_rstrncasecmp(h[i].key.data, "User-Agent", sizeof("User-Agent") - 1)
) {
ngx_memcpy(ngx_list_push(&sr->headers_in.headers), &h[i], sizeof(ngx_table_elt_t));
}
}
}

if (req_range && (piece_range->start < req_range->start || piece_range->end > req_range->end)) {
ngx_table_elt_t *range_header = ngx_list_push(&sr->headers_in.headers);
off_t start = req_range->start - piece_range->start;
Expand Down
2 changes: 1 addition & 1 deletion ngx_http_zip_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ ngx_http_zip_send_file_piece(ngx_http_request_t *r, ngx_http_zip_ctx_t *ctx,
return NGX_ERROR;
}

if ((sr_ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_zip_ctx_t))) == NULL) {
if ((sr_ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_zip_sr_ctx_t))) == NULL) {
return NGX_ERROR;
}

Expand Down

0 comments on commit f531c55

Please sign in to comment.