# HG changeset patch # User Igor Sysoev # Date 1241108107 0 # Node ID 4e002555652d06158a682cfb8226add8613d3a1d # Parent d478379e51ac235edeee3d3c697da12e1cb275cc proxy_ignore_headers and fastcgi_ignore_headers diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c --- a/src/http/modules/ngx_http_fastcgi_module.c +++ b/src/http/modules/ngx_http_fastcgi_module.c @@ -183,6 +183,15 @@ static ngx_conf_bitmask_t ngx_http_fast }; +static ngx_conf_bitmask_t ngx_http_fastcgi_ignore_headers_masks[] = { + { ngx_string("X-Accel-Redirect"), NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT }, + { ngx_string("X-Accel-Expires"), NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES }, + { ngx_string("Expires"), NGX_HTTP_UPSTREAM_IGN_EXPIRES }, + { ngx_string("Cache-Control"), NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL }, + { ngx_null_string, 0 } +}; + + ngx_module_t ngx_http_fastcgi_module; @@ -409,6 +418,13 @@ static ngx_command_t ngx_http_fastcgi_c offsetof(ngx_http_fastcgi_loc_conf_t, upstream.hide_headers), NULL }, + { ngx_string("fastcgi_ignore_headers"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, + ngx_conf_set_bitmask_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_headers), + &ngx_http_fastcgi_ignore_headers_masks }, + { ngx_string("fastcgi_catch_stderr"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_str_array_slot, @@ -1817,6 +1833,7 @@ ngx_http_fastcgi_create_loc_conf(ngx_con * set by ngx_pcalloc(): * * conf->upstream.bufs.num = 0; + * conf->upstream.ignore_headers = 0; * conf->upstream.next_upstream = 0; * conf->upstream.use_stale_cache = 0; * conf->upstream.temp_path = NULL; @@ -2012,6 +2029,11 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf } + ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers, + prev->upstream.ignore_headers, + NGX_CONF_BITMASK_SET); + + ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, prev->upstream.next_upstream, (NGX_CONF_BITMASK_SET diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -172,6 +172,15 @@ static ngx_conf_bitmask_t ngx_http_prox }; +static ngx_conf_bitmask_t ngx_http_proxy_ignore_headers_masks[] = { + { ngx_string("X-Accel-Redirect"), NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT }, + { ngx_string("X-Accel-Expires"), NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES }, + { ngx_string("Expires"), NGX_HTTP_UPSTREAM_IGN_EXPIRES }, + { ngx_string("Cache-Control"), NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL }, + { ngx_null_string, 0 } +}; + + ngx_module_t ngx_http_proxy_module; @@ -426,6 +435,13 @@ static ngx_command_t ngx_http_proxy_com offsetof(ngx_http_proxy_loc_conf_t, upstream.hide_headers), NULL }, + { ngx_string("proxy_ignore_headers"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, + ngx_conf_set_bitmask_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_headers), + &ngx_http_proxy_ignore_headers_masks }, + #if (NGX_HTTP_SSL) { ngx_string("proxy_ssl_session_reuse"), @@ -1867,6 +1883,7 @@ ngx_http_proxy_create_loc_conf(ngx_conf_ * set by ngx_pcalloc(): * * conf->upstream.bufs.num = 0; + * conf->upstream.ignore_headers = 0; * conf->upstream.next_upstream = 0; * conf->upstream.use_stale_cache = 0; * conf->upstream.temp_path = NULL; @@ -2072,6 +2089,11 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t } + ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers, + prev->upstream.ignore_headers, + NGX_CONF_BITMASK_SET); + + ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, prev->upstream.next_upstream, (NGX_CONF_BITMASK_SET diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -1623,8 +1623,9 @@ ngx_http_upstream_process_headers(ngx_ht umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); - if (u->headers_in.x_accel_redirect) { - + if (u->headers_in.x_accel_redirect + && !(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT)) + { ngx_http_upstream_finalize_request(r, u, NGX_DECLINED); part = &u->headers_in.headers.part; @@ -2845,10 +2846,12 @@ static ngx_int_t ngx_http_upstream_process_cache_control(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset) { - ngx_array_t *pa; - ngx_table_elt_t **ph; - - pa = &r->upstream->headers_in.cache_control; + ngx_array_t *pa; + ngx_table_elt_t **ph; + ngx_http_upstream_t *u; + + u = r->upstream; + pa = &u->headers_in.cache_control; if (pa->elts == NULL) { if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) @@ -2869,6 +2872,10 @@ ngx_http_upstream_process_cache_control( u_char *p, *last; ngx_int_t n; + if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL) { + return NGX_OK; + } + if (r->cache == NULL) { return NGX_OK; } @@ -2882,7 +2889,7 @@ ngx_http_upstream_process_cache_control( if (ngx_strlcasestrn(h->value.data, last, (u_char *) "no-cache", 8 - 1) != NULL) { - r->upstream->cacheable = 0; + u->cacheable = 0; return NGX_OK; } @@ -2904,12 +2911,12 @@ ngx_http_upstream_process_cache_control( continue; } - r->upstream->cacheable = 0; + u->cacheable = 0; return NGX_OK; } if (n == 0) { - r->upstream->cacheable = 0; + u->cacheable = 0; return NGX_OK; } @@ -2925,12 +2932,19 @@ static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset) { - r->upstream->headers_in.expires = h; + ngx_http_upstream_t *u; + + u = r->upstream; + u->headers_in.expires = h; #if (NGX_HTTP_CACHE) { time_t expires; + if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_EXPIRES) { + return NGX_OK; + } + if (r->cache == NULL) { return NGX_OK; } @@ -2942,7 +2956,7 @@ ngx_http_upstream_process_expires(ngx_ht expires = ngx_http_parse_time(h->value.data, h->value.len); if (expires == NGX_ERROR || expires < ngx_time()) { - r->upstream->cacheable = 0; + u->cacheable = 0; return NGX_OK; } @@ -2958,7 +2972,10 @@ static ngx_int_t ngx_http_upstream_process_accel_expires(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset) { - r->upstream->headers_in.x_accel_expires = h; + ngx_http_upstream_t *u; + + u = r->upstream; + u->headers_in.x_accel_expires = h; #if (NGX_HTTP_CACHE) { @@ -2966,6 +2983,10 @@ ngx_http_upstream_process_accel_expires( size_t len; ngx_int_t n; + if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES) { + return NGX_OK; + } + if (r->cache == NULL) { return NGX_OK; } @@ -2978,7 +2999,7 @@ ngx_http_upstream_process_accel_expires( switch (n) { case 0: - r->upstream->cacheable = 0; + u->cacheable = 0; case NGX_ERROR: return NGX_OK; diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h --- a/src/http/ngx_http_upstream.h +++ b/src/http/ngx_http_upstream.h @@ -38,6 +38,12 @@ #define NGX_HTTP_UPSTREAM_INVALID_HEADER 40 +#define NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT 0x00000002 +#define NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES 0x00000004 +#define NGX_HTTP_UPSTREAM_IGN_EXPIRES 0x00000008 +#define NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL 0x00000010 + + typedef struct { ngx_msec_t bl_time; ngx_uint_t bl_state; @@ -128,6 +134,7 @@ typedef struct { ngx_bufs_t bufs; + ngx_uint_t ignore_headers; ngx_uint_t next_upstream; ngx_uint_t store_access; ngx_flag_t buffering;