comparison src/http/ngx_http_upstream.c @ 1990:c7757ce0ae97 stable-0.5

r1699, r1700, r1701, r1702, r1707 merge: upstream parse_header fix and optimization, fix fastcgi_catch_stderr segfault merged in r1524: *) return NGX_HTTP_UPSTREAM_INVALID_HEADER for invalid status *) return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header() *) return NGX_HTTP_UPSTREAM_INVALID_HEADER instead of NGX_HTTP_BAD_GATEWAY to go to a next upstream on invalid_header condition *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR this fixes fastcgi_catch_stderr segfault *) ngx_http_upstream_hide_headers_hash() *) proxy/fastcgi pass_header/hide_header use ngx_http_upstream_hide_headers_hash()
author Igor Sysoev <igor@sysoev.ru>
date Sun, 04 May 2008 09:29:43 +0000
parents 6b81bbc36eaf
children ee49a83b6de2
comparison
equal deleted inserted replaced
1989:0ba9a893dd1a 1990:c7757ce0ae97
1039 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { 1039 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
1040 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); 1040 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
1041 return; 1041 return;
1042 } 1042 }
1043 1043
1044 if (rc == NGX_ERROR || rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { 1044 if (rc == NGX_ERROR) {
1045 ngx_http_upstream_finalize_request(r, u, 1045 ngx_http_upstream_finalize_request(r, u,
1046 NGX_HTTP_INTERNAL_SERVER_ERROR); 1046 NGX_HTTP_INTERNAL_SERVER_ERROR);
1047 return; 1047 return;
1048 } 1048 }
1049 1049
3263 3263
3264 return uscf; 3264 return uscf;
3265 } 3265 }
3266 3266
3267 3267
3268 ngx_int_t
3269 ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
3270 ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
3271 ngx_str_t *default_hide_headers, ngx_hash_init_t *hash)
3272 {
3273 ngx_str_t *h;
3274 ngx_uint_t i, j;
3275 ngx_array_t hide_headers;
3276 ngx_hash_key_t *hk;
3277
3278 if (conf->hide_headers == NGX_CONF_UNSET_PTR
3279 && conf->pass_headers == NGX_CONF_UNSET_PTR)
3280 {
3281 conf->hide_headers_hash = prev->hide_headers_hash;
3282
3283 if (conf->hide_headers_hash.buckets) {
3284 return NGX_OK;
3285 }
3286
3287 conf->hide_headers = prev->hide_headers;
3288 conf->pass_headers = prev->pass_headers;
3289
3290 } else {
3291 if (conf->hide_headers == NGX_CONF_UNSET_PTR) {
3292 conf->hide_headers = prev->hide_headers;
3293 }
3294
3295 if (conf->pass_headers == NGX_CONF_UNSET_PTR) {
3296 conf->pass_headers = prev->pass_headers;
3297 }
3298 }
3299
3300 if (ngx_array_init(&hide_headers, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
3301 != NGX_OK)
3302 {
3303 return NGX_ERROR;
3304 }
3305
3306 for (h = default_hide_headers; h->len; h++) {
3307 hk = ngx_array_push(&hide_headers);
3308 if (hk == NULL) {
3309 return NGX_ERROR;
3310 }
3311
3312 hk->key = *h;
3313 hk->key_hash = ngx_hash_key_lc(h->data, h->len);
3314 hk->value = (void *) 1;
3315 }
3316
3317 if (conf->hide_headers != NGX_CONF_UNSET_PTR) {
3318
3319 h = conf->hide_headers->elts;
3320
3321 for (i = 0; i < conf->hide_headers->nelts; i++) {
3322
3323 hk = hide_headers.elts;
3324
3325 for (j = 0; j < hide_headers.nelts; j++) {
3326 if (ngx_strcasecmp(h[i].data, hk[j].key.data) == 0) {
3327 goto exist;
3328 }
3329 }
3330
3331 hk = ngx_array_push(&hide_headers);
3332 if (hk == NULL) {
3333 return NGX_ERROR;
3334 }
3335
3336 hk->key = h[i];
3337 hk->key_hash = ngx_hash_key_lc(h[i].data, h[i].len);
3338 hk->value = (void *) 1;
3339
3340 exist:
3341
3342 continue;
3343 }
3344 }
3345
3346 if (conf->pass_headers != NGX_CONF_UNSET_PTR) {
3347
3348 h = conf->pass_headers->elts;
3349 hk = hide_headers.elts;
3350
3351 for (i = 0; i < conf->pass_headers->nelts; i++) {
3352 for (j = 0; j < hide_headers.nelts; j++) {
3353
3354 if (hk[j].key.data == NULL) {
3355 continue;
3356 }
3357
3358 if (ngx_strcasecmp(h[i].data, hk[j].key.data) == 0) {
3359 hk[j].key.data = NULL;
3360 break;
3361 }
3362 }
3363 }
3364 }
3365
3366 hash->hash = &conf->hide_headers_hash;
3367 hash->key = ngx_hash_key_lc;
3368 hash->pool = cf->pool;
3369 hash->temp_pool = NULL;
3370
3371 return ngx_hash_init(hash, hide_headers.elts, hide_headers.nelts);
3372 }
3373
3374
3268 static void * 3375 static void *
3269 ngx_http_upstream_create_main_conf(ngx_conf_t *cf) 3376 ngx_http_upstream_create_main_conf(ngx_conf_t *cf)
3270 { 3377 {
3271 ngx_http_upstream_main_conf_t *umcf; 3378 ngx_http_upstream_main_conf_t *umcf;
3272 3379