Skip to content

Commit 932eccf

Browse files
heikojansendavidjb
authored andcommitted
bugfix: update handling of multiple headers changed in nginx 1.23.0
This copies code contributed to ngx_headers_more by @hnakamur in openresty/headers-more-nginx-module@91eb0db
1 parent 74f9c37 commit 932eccf

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

ngx_http_shibboleth_module.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* Contains elements adapted from ngx_lua:
1010
* Copyright (C) 2009-2015, by Xiaozhe Wang (chaoslawful) chaoslawful@gmail.com.
1111
* Copyright (C) 2009-2015, by Yichun "agentzh" Zhang (章亦春) agentzh@gmail.com, CloudFlare Inc.
12+
* Contains elements adapted from ngx_headers_more:
13+
* Copyright (c) 2009-2017, Yichun "agentzh" Zhang (章亦春) agentzh@gmail.com, OpenResty Inc.
14+
* Copyright (c) 2010-2013, Bernd Dorn.
1215
*
1316
* Distributed under 2-clause BSD license, see LICENSE file.
1417
*/
@@ -840,6 +843,46 @@ static ngx_int_t
840843
ngx_http_set_builtin_multi_header(ngx_http_request_t *r,
841844
ngx_http_shib_request_header_val_t *hv, ngx_str_t *value)
842845
{
846+
#if defined(nginx_version) && nginx_version >= 1023000
847+
ngx_table_elt_t **headers, *h, *ho, **ph;
848+
849+
headers = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);
850+
851+
if (*headers) {
852+
for (h = (*headers)->next; h; h = h->next) {
853+
h->hash = 0;
854+
h->value.len = 0;
855+
}
856+
857+
h = *headers;
858+
859+
h->value = *value;
860+
861+
if (value->len == 0) {
862+
h->hash = 0;
863+
864+
} else {
865+
h->hash = hv->hash;
866+
}
867+
868+
return NGX_OK;
869+
}
870+
871+
for (ph = headers; *ph; ph = &(*ph)->next) { /* void */ }
872+
873+
ho = ngx_list_push(&r->headers_out.headers);
874+
if (ho == NULL) {
875+
return NGX_ERROR;
876+
}
877+
878+
ho->value = *value;
879+
ho->hash = hv->hash;
880+
ngx_str_set(&ho->key, "Cache-Control");
881+
ho->next = NULL;
882+
*ph = ho;
883+
884+
return NGX_OK;
885+
#else
843886
ngx_array_t *pa;
844887
ngx_table_elt_t *ho, **ph;
845888
ngx_uint_t i;
@@ -898,6 +941,7 @@ ngx_http_set_builtin_multi_header(ngx_http_request_t *r,
898941
*ph = ho;
899942

900943
return NGX_OK;
944+
#endif
901945
}
902946

903947

0 commit comments

Comments
 (0)