Skip to content

Commit

Permalink
Auth request: multiple WWW-Authenticate headers (ticket #485).
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdounin committed May 30, 2022
1 parent 87465e0 commit 911c95b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/http/modules/ngx_http_auth_request_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ngx_module_t ngx_http_auth_request_module = {
static ngx_int_t
ngx_http_auth_request_handler(ngx_http_request_t *r)
{
ngx_table_elt_t *h, *ho;
ngx_table_elt_t *h, *ho, **ph;
ngx_http_request_t *sr;
ngx_http_post_subrequest_t *ps;
ngx_http_auth_request_ctx_t *ctx;
Expand Down Expand Up @@ -147,7 +147,9 @@ ngx_http_auth_request_handler(ngx_http_request_t *r)
h = sr->upstream->headers_in.www_authenticate;
}

if (h) {
ph = &r->headers_out.www_authenticate;

while (h) {
ho = ngx_list_push(&r->headers_out.headers);
if (ho == NULL) {
return NGX_ERROR;
Expand All @@ -156,7 +158,10 @@ ngx_http_auth_request_handler(ngx_http_request_t *r)
*ho = *h;
ho->next = NULL;

r->headers_out.www_authenticate = ho;
*ph = ho;
ph = &ho->next;

h = h->next;
}

return ctx->status;
Expand Down

0 comments on commit 911c95b

Please sign in to comment.