comparison src/http/ngx_http_upstream.c @ 8036:f739c8142fb2

Upstream: multiple WWW-Authenticate headers (ticket #485). When using proxy_intercept_errors and an error page for error 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:53 +0300
parents cd73509f21e2
children e0cfab501dd1
comparison
equal deleted inserted replaced
8035:cd73509f21e2 8036:f739c8142fb2
2645 ngx_http_upstream_intercept_errors(ngx_http_request_t *r, 2645 ngx_http_upstream_intercept_errors(ngx_http_request_t *r,
2646 ngx_http_upstream_t *u) 2646 ngx_http_upstream_t *u)
2647 { 2647 {
2648 ngx_int_t status; 2648 ngx_int_t status;
2649 ngx_uint_t i; 2649 ngx_uint_t i;
2650 ngx_table_elt_t *h; 2650 ngx_table_elt_t *h, *ho, **ph;
2651 ngx_http_err_page_t *err_page; 2651 ngx_http_err_page_t *err_page;
2652 ngx_http_core_loc_conf_t *clcf; 2652 ngx_http_core_loc_conf_t *clcf;
2653 2653
2654 status = u->headers_in.status_n; 2654 status = u->headers_in.status_n;
2655 2655
2674 if (err_page[i].status == status) { 2674 if (err_page[i].status == status) {
2675 2675
2676 if (status == NGX_HTTP_UNAUTHORIZED 2676 if (status == NGX_HTTP_UNAUTHORIZED
2677 && u->headers_in.www_authenticate) 2677 && u->headers_in.www_authenticate)
2678 { 2678 {
2679 h = ngx_list_push(&r->headers_out.headers); 2679 h = u->headers_in.www_authenticate;
2680 2680 ph = &r->headers_out.www_authenticate;
2681 if (h == NULL) { 2681
2682 ngx_http_upstream_finalize_request(r, u, 2682 while (h) {
2683 ho = ngx_list_push(&r->headers_out.headers);
2684
2685 if (ho == NULL) {
2686 ngx_http_upstream_finalize_request(r, u,
2683 NGX_HTTP_INTERNAL_SERVER_ERROR); 2687 NGX_HTTP_INTERNAL_SERVER_ERROR);
2684 return NGX_OK; 2688 return NGX_OK;
2689 }
2690
2691 *ho = *h;
2692 ho->next = NULL;
2693
2694 *ph = ho;
2695 ph = &ho->next;
2696
2697 h = h->next;
2685 } 2698 }
2686
2687 *h = *u->headers_in.www_authenticate;
2688 h->next = NULL;
2689
2690 r->headers_out.www_authenticate = h;
2691 } 2699 }
2692 2700
2693 #if (NGX_HTTP_CACHE) 2701 #if (NGX_HTTP_CACHE)
2694 2702
2695 if (r->cache) { 2703 if (r->cache) {