Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_uwsgi_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 |
---|---|
23 | 23 |
24 typedef struct { | 24 typedef struct { |
25 ngx_http_upstream_conf_t upstream; | 25 ngx_http_upstream_conf_t upstream; |
26 | 26 |
27 ngx_http_uwsgi_params_t params; | 27 ngx_http_uwsgi_params_t params; |
28 #if (NGX_HTTP_CACHE) | |
29 ngx_http_uwsgi_params_t params_cache; | |
30 #endif | |
28 ngx_array_t *params_source; | 31 ngx_array_t *params_source; |
29 | 32 |
30 ngx_array_t *uwsgi_lengths; | 33 ngx_array_t *uwsgi_lengths; |
31 ngx_array_t *uwsgi_values; | 34 ngx_array_t *uwsgi_values; |
32 | 35 |
65 | 68 |
66 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf); | 69 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf); |
67 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, | 70 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, |
68 void *child); | 71 void *child); |
69 static ngx_int_t ngx_http_uwsgi_init_params(ngx_conf_t *cf, | 72 static ngx_int_t ngx_http_uwsgi_init_params(ngx_conf_t *cf, |
70 ngx_http_uwsgi_loc_conf_t *conf, ngx_http_uwsgi_params_t *params); | 73 ngx_http_uwsgi_loc_conf_t *conf, ngx_http_uwsgi_params_t *params, |
74 ngx_keyval_t *default_params); | |
71 | 75 |
72 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, | 76 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
73 void *conf); | 77 void *conf); |
74 static char *ngx_http_uwsgi_store(ngx_conf_t *cf, ngx_command_t *cmd, | 78 static char *ngx_http_uwsgi_store(ngx_conf_t *cf, ngx_command_t *cmd, |
75 void *conf); | 79 void *conf); |
793 header_params = 0; | 797 header_params = 0; |
794 ignored = NULL; | 798 ignored = NULL; |
795 | 799 |
796 uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module); | 800 uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module); |
797 | 801 |
802 #if (NGX_HTTP_CACHE) | |
803 params = r->upstream->cacheable ? &uwcf->params_cache : &uwcf->params; | |
804 #else | |
798 params = &uwcf->params; | 805 params = &uwcf->params; |
806 #endif | |
799 | 807 |
800 if (params->lengths) { | 808 if (params->lengths) { |
801 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | 809 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); |
802 | 810 |
803 ngx_http_script_flush_no_cacheable_variables(r, params->flushes); | 811 ngx_http_script_flush_no_cacheable_variables(r, params->flushes); |
1386 { | 1394 { |
1387 ngx_http_uwsgi_loc_conf_t *prev = parent; | 1395 ngx_http_uwsgi_loc_conf_t *prev = parent; |
1388 ngx_http_uwsgi_loc_conf_t *conf = child; | 1396 ngx_http_uwsgi_loc_conf_t *conf = child; |
1389 | 1397 |
1390 size_t size; | 1398 size_t size; |
1399 ngx_int_t rc; | |
1391 ngx_hash_init_t hash; | 1400 ngx_hash_init_t hash; |
1392 ngx_http_core_loc_conf_t *clcf; | 1401 ngx_http_core_loc_conf_t *clcf; |
1393 | 1402 |
1394 if (conf->upstream.store != 0) { | 1403 if (conf->upstream.store != 0) { |
1395 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0); | 1404 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0); |
1711 | 1720 |
1712 ngx_conf_merge_uint_value(conf->modifier1, prev->modifier1, 0); | 1721 ngx_conf_merge_uint_value(conf->modifier1, prev->modifier1, 0); |
1713 ngx_conf_merge_uint_value(conf->modifier2, prev->modifier2, 0); | 1722 ngx_conf_merge_uint_value(conf->modifier2, prev->modifier2, 0); |
1714 | 1723 |
1715 if (conf->params_source == NULL) { | 1724 if (conf->params_source == NULL) { |
1725 conf->params = prev->params; | |
1726 #if (NGX_HTTP_CACHE) | |
1727 conf->params_cache = prev->params_cache; | |
1728 #endif | |
1716 conf->params_source = prev->params_source; | 1729 conf->params_source = prev->params_source; |
1730 } | |
1731 | |
1732 rc = ngx_http_uwsgi_init_params(cf, conf, &conf->params, NULL); | |
1733 if (rc != NGX_OK) { | |
1734 return NGX_CONF_ERROR; | |
1735 } | |
1717 | 1736 |
1718 #if (NGX_HTTP_CACHE) | 1737 #if (NGX_HTTP_CACHE) |
1719 if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) | 1738 |
1720 #endif | 1739 if (conf->upstream.cache) { |
1721 { | 1740 rc = ngx_http_uwsgi_init_params(cf, conf, &conf->params_cache, |
1722 conf->params = prev->params; | 1741 ngx_http_uwsgi_cache_headers); |
1723 } | 1742 if (rc != NGX_OK) { |
1724 } | 1743 return NGX_CONF_ERROR; |
1725 | 1744 } |
1726 if (ngx_http_uwsgi_init_params(cf, conf, &conf->params) != NGX_OK) { | 1745 } |
1727 return NGX_CONF_ERROR; | 1746 |
1728 } | 1747 #endif |
1729 | 1748 |
1730 return NGX_CONF_OK; | 1749 return NGX_CONF_OK; |
1731 } | 1750 } |
1732 | 1751 |
1733 | 1752 |
1734 static ngx_int_t | 1753 static ngx_int_t |
1735 ngx_http_uwsgi_init_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf, | 1754 ngx_http_uwsgi_init_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf, |
1736 ngx_http_uwsgi_params_t *params) | 1755 ngx_http_uwsgi_params_t *params, ngx_keyval_t *default_params) |
1737 { | 1756 { |
1738 u_char *p; | 1757 u_char *p; |
1739 size_t size; | 1758 size_t size; |
1740 uintptr_t *code; | 1759 uintptr_t *code; |
1741 ngx_uint_t i, nsrc; | 1760 ngx_uint_t i, nsrc; |
1742 ngx_array_t headers_names; | 1761 ngx_array_t headers_names, params_merged; |
1743 #if (NGX_HTTP_CACHE) | 1762 ngx_keyval_t *h; |
1744 ngx_array_t params_merged; | |
1745 #endif | |
1746 ngx_hash_key_t *hk; | 1763 ngx_hash_key_t *hk; |
1747 ngx_hash_init_t hash; | 1764 ngx_hash_init_t hash; |
1748 ngx_http_upstream_param_t *src; | 1765 ngx_http_upstream_param_t *src, *s; |
1749 ngx_http_script_compile_t sc; | 1766 ngx_http_script_compile_t sc; |
1750 ngx_http_script_copy_code_t *copy; | 1767 ngx_http_script_copy_code_t *copy; |
1751 | 1768 |
1752 if (params->hash.buckets) { | 1769 if (params->hash.buckets) { |
1753 return NGX_OK; | 1770 return NGX_OK; |
1754 } | 1771 } |
1755 | 1772 |
1756 if (conf->params_source == NULL | 1773 if (conf->params_source == NULL && default_params == NULL) { |
1757 #if (NGX_HTTP_CACHE) | |
1758 && (conf->upstream.cache == NULL) | |
1759 #endif | |
1760 ) | |
1761 { | |
1762 params->hash.buckets = (void *) 1; | 1774 params->hash.buckets = (void *) 1; |
1763 return NGX_OK; | 1775 return NGX_OK; |
1764 } | 1776 } |
1765 | 1777 |
1766 params->lengths = ngx_array_create(cf->pool, 64, 1); | 1778 params->lengths = ngx_array_create(cf->pool, 64, 1); |
1786 } else { | 1798 } else { |
1787 src = NULL; | 1799 src = NULL; |
1788 nsrc = 0; | 1800 nsrc = 0; |
1789 } | 1801 } |
1790 | 1802 |
1791 #if (NGX_HTTP_CACHE) | 1803 if (default_params) { |
1792 | |
1793 if (conf->upstream.cache) { | |
1794 ngx_keyval_t *h; | |
1795 ngx_http_upstream_param_t *s; | |
1796 | |
1797 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, | 1804 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, |
1798 sizeof(ngx_http_upstream_param_t)) | 1805 sizeof(ngx_http_upstream_param_t)) |
1799 != NGX_OK) | 1806 != NGX_OK) |
1800 { | 1807 { |
1801 return NGX_ERROR; | 1808 return NGX_ERROR; |
1809 } | 1816 } |
1810 | 1817 |
1811 *s = src[i]; | 1818 *s = src[i]; |
1812 } | 1819 } |
1813 | 1820 |
1814 h = ngx_http_uwsgi_cache_headers; | 1821 h = default_params; |
1815 | 1822 |
1816 while (h->key.len) { | 1823 while (h->key.len) { |
1817 | 1824 |
1818 src = params_merged.elts; | 1825 src = params_merged.elts; |
1819 nsrc = params_merged.nelts; | 1826 nsrc = params_merged.nelts; |
1839 } | 1846 } |
1840 | 1847 |
1841 src = params_merged.elts; | 1848 src = params_merged.elts; |
1842 nsrc = params_merged.nelts; | 1849 nsrc = params_merged.nelts; |
1843 } | 1850 } |
1844 | |
1845 #endif | |
1846 | 1851 |
1847 for (i = 0; i < nsrc; i++) { | 1852 for (i = 0; i < nsrc; i++) { |
1848 | 1853 |
1849 if (src[i].key.len > sizeof("HTTP_") - 1 | 1854 if (src[i].key.len > sizeof("HTTP_") - 1 |
1850 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) | 1855 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) |