comparison src/http/modules/ngx_http_auth_request_module.c @ 8037:8272c823a7d0

Auth request: multiple WWW-Authenticate headers (ticket #485). When using auth_request with an upstream server which returns 401 (Unauthorized), multiple WWW-Authenticate headers from the upstream server response are now properly copied to the response.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:25:54 +0300
parents d26db4f82d7d
children
comparison
equal deleted inserted replaced
8036:f739c8142fb2 8037:8272c823a7d0
99 99
100 100
101 static ngx_int_t 101 static ngx_int_t
102 ngx_http_auth_request_handler(ngx_http_request_t *r) 102 ngx_http_auth_request_handler(ngx_http_request_t *r)
103 { 103 {
104 ngx_table_elt_t *h, *ho; 104 ngx_table_elt_t *h, *ho, **ph;
105 ngx_http_request_t *sr; 105 ngx_http_request_t *sr;
106 ngx_http_post_subrequest_t *ps; 106 ngx_http_post_subrequest_t *ps;
107 ngx_http_auth_request_ctx_t *ctx; 107 ngx_http_auth_request_ctx_t *ctx;
108 ngx_http_auth_request_conf_t *arcf; 108 ngx_http_auth_request_conf_t *arcf;
109 109
145 145
146 if (!h && sr->upstream) { 146 if (!h && sr->upstream) {
147 h = sr->upstream->headers_in.www_authenticate; 147 h = sr->upstream->headers_in.www_authenticate;
148 } 148 }
149 149
150 if (h) { 150 ph = &r->headers_out.www_authenticate;
151
152 while (h) {
151 ho = ngx_list_push(&r->headers_out.headers); 153 ho = ngx_list_push(&r->headers_out.headers);
152 if (ho == NULL) { 154 if (ho == NULL) {
153 return NGX_ERROR; 155 return NGX_ERROR;
154 } 156 }
155 157
156 *ho = *h; 158 *ho = *h;
157 ho->next = NULL; 159 ho->next = NULL;
158 160
159 r->headers_out.www_authenticate = ho; 161 *ph = ho;
162 ph = &ho->next;
163
164 h = h->next;
160 } 165 }
161 166
162 return ctx->status; 167 return ctx->status;
163 } 168 }
164 169