Ticket #485: patch.485.diff

File patch.485.diff, 6.7 KB (added by David Carlier, 12 years ago)
  • src/http/modules/ngx_http_auth_basic_module.c

    diff -r 42114bf12da0 src/http/modules/ngx_http_auth_basic_module.c
    a b ngx_http_auth_basic_set_realm(ngx_http_r  
    351351{
    352352    size_t   len;
    353353    u_char  *basic, *p;
     354    ngx_table_elt_t **wwauth;
    354355
    355     r->headers_out.www_authenticate = ngx_list_push(&r->headers_out.headers);
    356     if (r->headers_out.www_authenticate == NULL) {
     356    wwauth = r->headers_out.www_authenticate.elts;
     357    if (wwauth == NULL) {
     358        if (ngx_array_init(&r->headers_out.www_authenticate, r->pool,
     359                           1, sizeof(ngx_table_elt_t *)) != NGX_OK) {
     360            return NGX_HTTP_INTERNAL_SERVER_ERROR;
     361        }
     362   
     363        wwauth = ngx_array_push(&r->headers_out.www_authenticate);
     364       
     365        if (wwauth == NULL) {
     366            return NGX_HTTP_INTERNAL_SERVER_ERROR;
     367        }
     368    }
     369
     370    *wwauth = ngx_list_push(&r->headers_out.headers);
     371    if (*wwauth == NULL) {
    357372        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    358373    }
    359374
    ngx_http_auth_basic_set_realm(ngx_http_r  
    368383    p = ngx_cpymem(p, realm->data, realm->len);
    369384    *p = '"';
    370385
    371     r->headers_out.www_authenticate->hash = 1;
    372     ngx_str_set(&r->headers_out.www_authenticate->key, "WWW-Authenticate");
    373     r->headers_out.www_authenticate->value.data = basic;
    374     r->headers_out.www_authenticate->value.len = len;
     386    (*wwauth)->hash = 1;
     387    ngx_str_set(&(*wwauth)->key, "WWW-Authenticate");
     388    (*wwauth)->value.data = basic;
     389    (*wwauth)->value.len = len;
    375390
    376391    return NGX_HTTP_UNAUTHORIZED;
    377392}
  • src/http/modules/ngx_http_auth_request_module.c

    diff -r 42114bf12da0 src/http/modules/ngx_http_auth_request_module.c
    a b ngx_module_t ngx_http_auth_request_modu  
    101101static ngx_int_t
    102102ngx_http_auth_request_handler(ngx_http_request_t *r)
    103103{
    104     ngx_table_elt_t               *h, *ho;
     104    ngx_table_elt_t               *h, *ho, **hh;
    105105    ngx_http_request_t            *sr;
    106106    ngx_http_post_subrequest_t    *ps;
    107107    ngx_http_auth_request_ctx_t   *ctx;
    ngx_http_auth_request_handler(ngx_http_r  
    140140
    141141        if (ctx->status == NGX_HTTP_UNAUTHORIZED) {
    142142            sr = ctx->subrequest;
    143 
    144             h = sr->headers_out.www_authenticate;
     143            h = NULL;
     144            if (sr->headers_out.www_authenticate.elts != NULL) {
     145                hh = sr->headers_out.www_authenticate.elts;
     146                h = *hh;
     147            }
    145148
    146149            if (!h && sr->upstream) {
    147150                h = sr->upstream->headers_in.www_authenticate;
    ngx_http_auth_request_handler(ngx_http_r  
    153156                    return NGX_ERROR;
    154157                }
    155158
     159                hh = r->headers_out.www_authenticate.elts;
     160                if (hh == NULL) {
     161                    if (ngx_array_init(&r->headers_out.www_authenticate, r->pool,
     162                                       1, sizeof(ngx_table_elt_t *)) != NGX_OK) {
     163                        return NGX_ERROR;
     164                    }
     165
     166                    hh = ngx_array_push(&r->headers_out.www_authenticate);
     167                    if (hh == NULL) {
     168                        return NGX_ERROR;
     169                    }
     170                }             
     171
    156172                *ho = *h;
    157 
    158                 r->headers_out.www_authenticate = ho;
     173                *hh = ho;
    159174            }
    160175
    161176            return ctx->status;
  • src/http/ngx_http_core_module.c

    diff -r 42114bf12da0 src/http/ngx_http_core_module.c
    a b ngx_int_t  
    11011101ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
    11021102{
    11031103    ngx_int_t                  rc;
     1104    ngx_uint_t                 i;
    11041105    ngx_http_core_loc_conf_t  *clcf;
     1106    ngx_table_elt_t           **wwauth;
    11051107
    11061108    if (r != r->main) {
    11071109        r->phase_handler = ph->next;
    ngx_http_core_access_phase(ngx_http_requ  
    11351137        if (rc == NGX_OK) {
    11361138            r->access_code = 0;
    11371139
    1138             if (r->headers_out.www_authenticate) {
    1139                 r->headers_out.www_authenticate->hash = 0;
     1140            if (r->headers_out.www_authenticate.elts) {
     1141                wwauth = r->headers_out.www_authenticate.elts;
     1142
     1143                for (i = 0; i < r->headers_out.www_authenticate.nelts; i++) {
     1144                    wwauth[i]->hash = 0;
     1145                }
    11401146            }
    11411147
    11421148            r->phase_handler = ph->next;
  • src/http/ngx_http_request.h

    diff -r 42114bf12da0 src/http/ngx_http_request.h
    a b typedef struct {  
    255255    ngx_table_elt_t                  *last_modified;
    256256    ngx_table_elt_t                  *content_range;
    257257    ngx_table_elt_t                  *accept_ranges;
    258     ngx_table_elt_t                  *www_authenticate;
    259258    ngx_table_elt_t                  *expires;
    260259    ngx_table_elt_t                  *etag;
    261260
    typedef struct {  
    268267    ngx_uint_t                        content_type_hash;
    269268
    270269    ngx_array_t                       cache_control;
     270    ngx_array_t                       www_authenticate;
    271271
    272272    off_t                             content_length_n;
    273273    time_t                            date_time;
  • src/http/ngx_http_upstream.c

    diff -r 42114bf12da0 src/http/ngx_http_upstream.c
    a b ngx_http_upstream_intercept_errors(ngx_h  
    20102010{
    20112011    ngx_int_t                  status;
    20122012    ngx_uint_t                 i;
    2013     ngx_table_elt_t           *h;
     2013    ngx_table_elt_t           *h, **wwauth;
    20142014    ngx_http_err_page_t       *err_page;
    20152015    ngx_http_core_loc_conf_t  *clcf;
    20162016
    ngx_http_upstream_intercept_errors(ngx_h  
    20482048                }
    20492049
    20502050                *h = *u->headers_in.www_authenticate;
    2051 
    2052                 r->headers_out.www_authenticate = h;
     2051                wwauth = r->headers_out.www_authenticate.elts;
     2052
     2053                if (wwauth == NULL) {
     2054                    if (ngx_array_init(&r->headers_out.www_authenticate,
     2055                                       r->pool, 1,
     2056                                       sizeof(ngx_table_elt_t *)) != NGX_OK) {
     2057                        return NGX_ERROR;
     2058                    }
     2059
     2060                    wwauth = ngx_array_push(&r->headers_out.www_authenticate);
     2061
     2062                    if (wwauth == NULL) {
     2063                        return NGX_ERROR;
     2064                    }
     2065                }
     2066
     2067                *wwauth = h;
    20532068            }
    20542069
    20552070#if (NGX_HTTP_CACHE)