Skip to content

Commit 91eb0db

Browse files
hnakamurzhuizhuhaomeng
authored andcommitted
bugfix: update handling of multiple headers changed in nginx 1.23.0.
1 parent e536bc5 commit 91eb0db

4 files changed

+91
-0
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ env:
2323
matrix:
2424
- NGINX_VERSION=1.19.3
2525
- NGINX_VERSION=1.19.9
26+
- NGINX_VERSION=1.23.0
2627

2728
before_install:
2829
- sudo apt-get update -y
@@ -51,3 +52,4 @@ script:
5152
- export NGX_BUILD_CC=$CC
5253
- sh util/build.sh $NGINX_VERSION > build.log 2>&1 || (cat build.log && exit 1)
5354
- prove -I. -r t
55+

src/ngx_http_headers_more_headers_in.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,50 @@ static ngx_int_t
758758
ngx_http_set_builtin_multi_header(ngx_http_request_t *r,
759759
ngx_http_headers_more_header_val_t *hv, ngx_str_t *value)
760760
{
761+
#if defined(nginx_version) && nginx_version >= 1023000
762+
ngx_table_elt_t **headers, **ph, *h;
763+
int nelts;
764+
765+
if (r->headers_out.status == 400 || r->headers_in.headers.last == NULL) {
766+
/* must be a 400 Bad Request */
767+
return NGX_OK;
768+
}
769+
770+
headers = (ngx_table_elt_t **) ((char *) &r->headers_in + hv->offset);
771+
772+
if (*headers) {
773+
nelts = 0;
774+
for (h = *headers; h; h = h->next) {
775+
nelts++;
776+
}
777+
778+
*headers = NULL;
779+
780+
dd("clear multi-value headers: %d", nelts);
781+
}
782+
783+
if (ngx_http_set_header_helper(r, hv, value, &h) == NGX_ERROR) {
784+
return NGX_ERROR;
785+
}
786+
787+
if (value->len == 0) {
788+
return NGX_OK;
789+
}
790+
791+
dd("new multi-value header: %p", h);
792+
793+
if (*headers) {
794+
for (ph = headers; *ph; ph = &(*ph)->next) { /* void */ }
795+
*ph = h;
796+
797+
} else {
798+
*headers = h;
799+
}
800+
801+
h->next = NULL;
802+
803+
return NGX_OK;
804+
#else
761805
ngx_array_t *headers;
762806
ngx_table_elt_t **v, *h;
763807

@@ -810,6 +854,7 @@ ngx_http_set_builtin_multi_header(ngx_http_request_t *r,
810854

811855
*v = h;
812856
return NGX_OK;
857+
#endif
813858
}
814859

815860

@@ -842,6 +887,7 @@ ngx_http_headers_more_validate_host(ngx_str_t *host, ngx_pool_t *pool,
842887
if (dot_pos == i - 1) {
843888
return NGX_DECLINED;
844889
}
890+
845891
dot_pos = i;
846892
break;
847893

src/ngx_http_headers_more_headers_out.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,46 @@ static ngx_int_t
327327
ngx_http_set_builtin_multi_header(ngx_http_request_t *r,
328328
ngx_http_headers_more_header_val_t *hv, ngx_str_t *value)
329329
{
330+
#if defined(nginx_version) && nginx_version >= 1023000
331+
ngx_table_elt_t **headers, *h, *ho, **ph;
332+
333+
headers = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);
334+
335+
if (*headers) {
336+
for (h = (*headers)->next; h; h = h->next) {
337+
h->hash = 0;
338+
h->value.len = 0;
339+
}
340+
341+
h = *headers;
342+
343+
h->value = *value;
344+
345+
if (value->len == 0) {
346+
h->hash = 0;
347+
348+
} else {
349+
h->hash = hv->hash;
350+
}
351+
352+
return NGX_OK;
353+
}
354+
355+
for (ph = headers; *ph; ph = &(*ph)->next) { /* void */ }
356+
357+
ho = ngx_list_push(&r->headers_out.headers);
358+
if (ho == NULL) {
359+
return NGX_ERROR;
360+
}
361+
362+
ho->value = *value;
363+
ho->hash = hv->hash;
364+
ngx_str_set(&ho->key, "Cache-Control");
365+
ho->next = NULL;
366+
*ph = ho;
367+
368+
return NGX_OK;
369+
#else
330370
ngx_array_t *pa;
331371
ngx_table_elt_t *ho, **ph;
332372
ngx_uint_t i;
@@ -378,6 +418,7 @@ ngx_http_set_builtin_multi_header(ngx_http_request_t *r,
378418
*ph = ho;
379419

380420
return NGX_OK;
421+
#endif
381422
}
382423

383424

src/ngx_http_headers_more_util.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ ngx_http_headers_more_rm_header_helper(ngx_list_t *l, ngx_list_part_t *cur,
295295
if (part->next == NULL) {
296296
return NGX_ERROR;
297297
}
298+
298299
part = part->next;
299300
}
300301

@@ -338,6 +339,7 @@ ngx_http_headers_more_rm_header_helper(ngx_list_t *l, ngx_list_part_t *cur,
338339
if (part->next == NULL) {
339340
return NGX_ERROR;
340341
}
342+
341343
part = part->next;
342344
}
343345

0 commit comments

Comments
 (0)