comparison src/http/ngx_http_upstream.c @ 8035:cd73509f21e2

Upstream: handling of multiple Vary headers (ticket #1423). Previously, only the last header value was used when caching.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:25:51 +0300
parents 413dbda22f7d
children f739c8142fb2
comparison
equal deleted inserted replaced
8034:413dbda22f7d 8035:cd73509f21e2
5173 5173
5174 static ngx_int_t 5174 static ngx_int_t
5175 ngx_http_upstream_process_vary(ngx_http_request_t *r, 5175 ngx_http_upstream_process_vary(ngx_http_request_t *r,
5176 ngx_table_elt_t *h, ngx_uint_t offset) 5176 ngx_table_elt_t *h, ngx_uint_t offset)
5177 { 5177 {
5178 u_char *p;
5179 size_t len;
5180 ngx_str_t vary;
5178 ngx_table_elt_t **ph; 5181 ngx_table_elt_t **ph;
5179 ngx_http_upstream_t *u; 5182 ngx_http_upstream_t *u;
5180 5183
5181 u = r->upstream; 5184 u = r->upstream;
5182 ph = &u->headers_in.vary; 5185 ph = &u->headers_in.vary;
5190 5193
5191 if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_VARY) { 5194 if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_VARY) {
5192 return NGX_OK; 5195 return NGX_OK;
5193 } 5196 }
5194 5197
5195 if (r->cache == NULL) { 5198 if (r->cache == NULL || !u->cacheable) {
5196 return NGX_OK; 5199 return NGX_OK;
5197 } 5200 }
5198 5201
5199 if (h->value.len > NGX_HTTP_CACHE_VARY_LEN 5202 if (h->value.len == 1 && h->value.data[0] == '*') {
5200 || (h->value.len == 1 && h->value.data[0] == '*'))
5201 {
5202 u->cacheable = 0; 5203 u->cacheable = 0;
5203 } 5204 return NGX_OK;
5204 5205 }
5205 r->cache->vary = h->value; 5206
5207 if (u->headers_in.vary->next) {
5208
5209 len = 0;
5210
5211 for (h = u->headers_in.vary; h; h = h->next) {
5212 len += h->value.len + 2;
5213 }
5214
5215 len -= 2;
5216
5217 p = ngx_pnalloc(r->pool, len);
5218 if (p == NULL) {
5219 return NGX_ERROR;
5220 }
5221
5222 vary.len = len;
5223 vary.data = p;
5224
5225 for (h = u->headers_in.vary; h; h = h->next) {
5226 p = ngx_copy(p, h->value.data, h->value.len);
5227
5228 if (h->next == NULL) {
5229 break;
5230 }
5231
5232 *p++ = ','; *p++ = ' ';
5233 }
5234
5235 } else {
5236 vary = h->value;
5237 }
5238
5239 if (vary.len > NGX_HTTP_CACHE_VARY_LEN) {
5240 u->cacheable = 0;
5241 }
5242
5243 r->cache->vary = vary;
5206 5244
5207 #endif 5245 #endif
5208 5246
5209 return NGX_OK; 5247 return NGX_OK;
5210 } 5248 }