Mercurial > hg > nginx
comparison src/http/modules/ngx_http_scgi_module.c @ 5909:8d0cf26ce071
Upstream: different header lists for cached and uncached requests.
The upstream modules remove and alter a number of client headers
before sending the request to upstream. This set of headers is
smaller or even empty when cache is disabled.
It's still possible that a request in a cache-enabled location is
uncached, for example, if cache entry counter is below min_uses.
In this case it's better to alter a smaller set of headers and
pass more client headers to backend unchanged. One of the benefits
is enabling server-side byte ranges in such requests.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Wed, 19 Nov 2014 17:33:23 +0300 |
parents | f8e80f8c7fc7 |
children | 5b9f711dc819 |
comparison
equal
deleted
inserted
replaced
5908:f8e80f8c7fc7 | 5909:8d0cf26ce071 |
---|---|
22 | 22 |
23 typedef struct { | 23 typedef struct { |
24 ngx_http_upstream_conf_t upstream; | 24 ngx_http_upstream_conf_t upstream; |
25 | 25 |
26 ngx_http_scgi_params_t params; | 26 ngx_http_scgi_params_t params; |
27 #if (NGX_HTTP_CACHE) | |
28 ngx_http_scgi_params_t params_cache; | |
29 #endif | |
27 ngx_array_t *params_source; | 30 ngx_array_t *params_source; |
28 | 31 |
29 ngx_array_t *scgi_lengths; | 32 ngx_array_t *scgi_lengths; |
30 ngx_array_t *scgi_values; | 33 ngx_array_t *scgi_values; |
31 | 34 |
46 | 49 |
47 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); | 50 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); |
48 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, | 51 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, |
49 void *child); | 52 void *child); |
50 static ngx_int_t ngx_http_scgi_init_params(ngx_conf_t *cf, | 53 static ngx_int_t ngx_http_scgi_init_params(ngx_conf_t *cf, |
51 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_params_t *params); | 54 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_params_t *params, |
55 ngx_keyval_t *default_params); | |
52 | 56 |
53 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 57 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
54 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, | 58 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, |
55 void *conf); | 59 void *conf); |
56 | 60 |
606 header_params = 0; | 610 header_params = 0; |
607 ignored = NULL; | 611 ignored = NULL; |
608 | 612 |
609 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module); | 613 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module); |
610 | 614 |
615 #if (NGX_HTTP_CACHE) | |
616 params = r->upstream->cacheable ? &scf->params_cache : &scf->params; | |
617 #else | |
611 params = &scf->params; | 618 params = &scf->params; |
619 #endif | |
612 | 620 |
613 if (params->lengths) { | 621 if (params->lengths) { |
614 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | 622 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); |
615 | 623 |
616 ngx_http_script_flush_no_cacheable_variables(r, params->flushes); | 624 ngx_http_script_flush_no_cacheable_variables(r, params->flushes); |
1172 { | 1180 { |
1173 ngx_http_scgi_loc_conf_t *prev = parent; | 1181 ngx_http_scgi_loc_conf_t *prev = parent; |
1174 ngx_http_scgi_loc_conf_t *conf = child; | 1182 ngx_http_scgi_loc_conf_t *conf = child; |
1175 | 1183 |
1176 size_t size; | 1184 size_t size; |
1185 ngx_int_t rc; | |
1177 ngx_hash_init_t hash; | 1186 ngx_hash_init_t hash; |
1178 ngx_http_core_loc_conf_t *clcf; | 1187 ngx_http_core_loc_conf_t *clcf; |
1179 | 1188 |
1180 if (conf->upstream.store != 0) { | 1189 if (conf->upstream.store != 0) { |
1181 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0); | 1190 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0); |
1449 clcf->handler = ngx_http_scgi_handler; | 1458 clcf->handler = ngx_http_scgi_handler; |
1450 } | 1459 } |
1451 } | 1460 } |
1452 | 1461 |
1453 if (conf->params_source == NULL) { | 1462 if (conf->params_source == NULL) { |
1463 conf->params = prev->params; | |
1464 #if (NGX_HTTP_CACHE) | |
1465 conf->params_cache = prev->params_cache; | |
1466 #endif | |
1454 conf->params_source = prev->params_source; | 1467 conf->params_source = prev->params_source; |
1468 } | |
1469 | |
1470 rc = ngx_http_scgi_init_params(cf, conf, &conf->params, NULL); | |
1471 if (rc != NGX_OK) { | |
1472 return NGX_CONF_ERROR; | |
1473 } | |
1455 | 1474 |
1456 #if (NGX_HTTP_CACHE) | 1475 #if (NGX_HTTP_CACHE) |
1457 if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) | 1476 |
1477 if (conf->upstream.cache) { | |
1478 rc = ngx_http_scgi_init_params(cf, conf, &conf->params_cache, | |
1479 ngx_http_scgi_cache_headers); | |
1480 if (rc != NGX_OK) { | |
1481 return NGX_CONF_ERROR; | |
1482 } | |
1483 } | |
1484 | |
1458 #endif | 1485 #endif |
1459 { | |
1460 conf->params = prev->params; | |
1461 } | |
1462 } | |
1463 | |
1464 if (ngx_http_scgi_init_params(cf, conf, &conf->params) != NGX_OK) { | |
1465 return NGX_CONF_ERROR; | |
1466 } | |
1467 | 1486 |
1468 return NGX_CONF_OK; | 1487 return NGX_CONF_OK; |
1469 } | 1488 } |
1470 | 1489 |
1471 | 1490 |
1472 static ngx_int_t | 1491 static ngx_int_t |
1473 ngx_http_scgi_init_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf, | 1492 ngx_http_scgi_init_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf, |
1474 ngx_http_scgi_params_t *params) | 1493 ngx_http_scgi_params_t *params, ngx_keyval_t *default_params) |
1475 { | 1494 { |
1476 u_char *p; | 1495 u_char *p; |
1477 size_t size; | 1496 size_t size; |
1478 uintptr_t *code; | 1497 uintptr_t *code; |
1479 ngx_uint_t i, nsrc; | 1498 ngx_uint_t i, nsrc; |
1480 ngx_array_t headers_names; | 1499 ngx_array_t headers_names, params_merged; |
1481 #if (NGX_HTTP_CACHE) | 1500 ngx_keyval_t *h; |
1482 ngx_array_t params_merged; | |
1483 #endif | |
1484 ngx_hash_key_t *hk; | 1501 ngx_hash_key_t *hk; |
1485 ngx_hash_init_t hash; | 1502 ngx_hash_init_t hash; |
1486 ngx_http_upstream_param_t *src; | 1503 ngx_http_upstream_param_t *src, *s; |
1487 ngx_http_script_compile_t sc; | 1504 ngx_http_script_compile_t sc; |
1488 ngx_http_script_copy_code_t *copy; | 1505 ngx_http_script_copy_code_t *copy; |
1489 | 1506 |
1490 if (params->hash.buckets) { | 1507 if (params->hash.buckets) { |
1491 return NGX_OK; | 1508 return NGX_OK; |
1492 } | 1509 } |
1493 | 1510 |
1494 if (conf->params_source == NULL | 1511 if (conf->params_source == NULL && default_params == NULL) { |
1495 #if (NGX_HTTP_CACHE) | |
1496 && (conf->upstream.cache == NULL) | |
1497 #endif | |
1498 ) | |
1499 { | |
1500 params->hash.buckets = (void *) 1; | 1512 params->hash.buckets = (void *) 1; |
1501 return NGX_OK; | 1513 return NGX_OK; |
1502 } | 1514 } |
1503 | 1515 |
1504 params->lengths = ngx_array_create(cf->pool, 64, 1); | 1516 params->lengths = ngx_array_create(cf->pool, 64, 1); |
1524 } else { | 1536 } else { |
1525 src = NULL; | 1537 src = NULL; |
1526 nsrc = 0; | 1538 nsrc = 0; |
1527 } | 1539 } |
1528 | 1540 |
1529 #if (NGX_HTTP_CACHE) | 1541 if (default_params) { |
1530 | |
1531 if (conf->upstream.cache) { | |
1532 ngx_keyval_t *h; | |
1533 ngx_http_upstream_param_t *s; | |
1534 | |
1535 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, | 1542 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, |
1536 sizeof(ngx_http_upstream_param_t)) | 1543 sizeof(ngx_http_upstream_param_t)) |
1537 != NGX_OK) | 1544 != NGX_OK) |
1538 { | 1545 { |
1539 return NGX_ERROR; | 1546 return NGX_ERROR; |
1547 } | 1554 } |
1548 | 1555 |
1549 *s = src[i]; | 1556 *s = src[i]; |
1550 } | 1557 } |
1551 | 1558 |
1552 h = ngx_http_scgi_cache_headers; | 1559 h = default_params; |
1553 | 1560 |
1554 while (h->key.len) { | 1561 while (h->key.len) { |
1555 | 1562 |
1556 src = params_merged.elts; | 1563 src = params_merged.elts; |
1557 nsrc = params_merged.nelts; | 1564 nsrc = params_merged.nelts; |
1577 } | 1584 } |
1578 | 1585 |
1579 src = params_merged.elts; | 1586 src = params_merged.elts; |
1580 nsrc = params_merged.nelts; | 1587 nsrc = params_merged.nelts; |
1581 } | 1588 } |
1582 | |
1583 #endif | |
1584 | 1589 |
1585 for (i = 0; i < nsrc; i++) { | 1590 for (i = 0; i < nsrc; i++) { |
1586 | 1591 |
1587 if (src[i].key.len > sizeof("HTTP_") - 1 | 1592 if (src[i].key.len > sizeof("HTTP_") - 1 |
1588 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) | 1593 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) |