Mercurial > hg > nginx
comparison src/http/modules/ngx_http_uwsgi_module.c @ 5951:610832763648
Upstream: added variables support to proxy_cache and friends.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 22 Dec 2014 12:59:09 +0300 |
parents | 634da79665d3 |
children | b6eb6ec4fbd9 |
comparison
equal
deleted
inserted
replaced
5950:eaeecf00d5d7 | 5951:610832763648 |
---|---|
8 | 8 |
9 | 9 |
10 #include <ngx_config.h> | 10 #include <ngx_config.h> |
11 #include <ngx_core.h> | 11 #include <ngx_core.h> |
12 #include <ngx_http.h> | 12 #include <ngx_http.h> |
13 | |
14 | |
15 typedef struct { | |
16 ngx_array_t caches; /* ngx_http_file_cache_t * */ | |
17 } ngx_http_uwsgi_main_conf_t; | |
13 | 18 |
14 | 19 |
15 typedef struct { | 20 typedef struct { |
16 ngx_array_t *flushes; | 21 ngx_array_t *flushes; |
17 ngx_array_t *lengths; | 22 ngx_array_t *lengths; |
64 static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r); | 69 static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r); |
65 static void ngx_http_uwsgi_abort_request(ngx_http_request_t *r); | 70 static void ngx_http_uwsgi_abort_request(ngx_http_request_t *r); |
66 static void ngx_http_uwsgi_finalize_request(ngx_http_request_t *r, | 71 static void ngx_http_uwsgi_finalize_request(ngx_http_request_t *r, |
67 ngx_int_t rc); | 72 ngx_int_t rc); |
68 | 73 |
74 static void *ngx_http_uwsgi_create_main_conf(ngx_conf_t *cf); | |
69 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf); | 75 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf); |
70 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, | 76 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, |
71 void *child); | 77 void *child); |
72 static ngx_int_t ngx_http_uwsgi_init_params(ngx_conf_t *cf, | 78 static ngx_int_t ngx_http_uwsgi_init_params(ngx_conf_t *cf, |
73 ngx_http_uwsgi_loc_conf_t *conf, ngx_http_uwsgi_params_t *params, | 79 ngx_http_uwsgi_loc_conf_t *conf, ngx_http_uwsgi_params_t *params, |
282 NULL }, | 288 NULL }, |
283 | 289 |
284 { ngx_string("uwsgi_cache_path"), | 290 { ngx_string("uwsgi_cache_path"), |
285 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, | 291 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, |
286 ngx_http_file_cache_set_slot, | 292 ngx_http_file_cache_set_slot, |
287 0, | 293 NGX_HTTP_MAIN_CONF_OFFSET, |
288 0, | 294 offsetof(ngx_http_uwsgi_main_conf_t, caches), |
289 &ngx_http_uwsgi_module }, | 295 &ngx_http_uwsgi_module }, |
290 | 296 |
291 { ngx_string("uwsgi_cache_bypass"), | 297 { ngx_string("uwsgi_cache_bypass"), |
292 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | 298 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
293 ngx_http_set_predicate_slot, | 299 ngx_http_set_predicate_slot, |
531 | 537 |
532 static ngx_http_module_t ngx_http_uwsgi_module_ctx = { | 538 static ngx_http_module_t ngx_http_uwsgi_module_ctx = { |
533 NULL, /* preconfiguration */ | 539 NULL, /* preconfiguration */ |
534 NULL, /* postconfiguration */ | 540 NULL, /* postconfiguration */ |
535 | 541 |
536 NULL, /* create main configuration */ | 542 ngx_http_uwsgi_create_main_conf, /* create main configuration */ |
537 NULL, /* init main configuration */ | 543 NULL, /* init main configuration */ |
538 | 544 |
539 NULL, /* create server configuration */ | 545 NULL, /* create server configuration */ |
540 NULL, /* merge server configuration */ | 546 NULL, /* merge server configuration */ |
541 | 547 |
592 | 598 |
593 | 599 |
594 static ngx_int_t | 600 static ngx_int_t |
595 ngx_http_uwsgi_handler(ngx_http_request_t *r) | 601 ngx_http_uwsgi_handler(ngx_http_request_t *r) |
596 { | 602 { |
597 ngx_int_t rc; | 603 ngx_int_t rc; |
598 ngx_http_status_t *status; | 604 ngx_http_status_t *status; |
599 ngx_http_upstream_t *u; | 605 ngx_http_upstream_t *u; |
600 ngx_http_uwsgi_loc_conf_t *uwcf; | 606 ngx_http_uwsgi_loc_conf_t *uwcf; |
607 #if (NGX_HTTP_CACHE) | |
608 ngx_http_uwsgi_main_conf_t *uwmcf; | |
609 #endif | |
601 | 610 |
602 if (ngx_http_upstream_create(r) != NGX_OK) { | 611 if (ngx_http_upstream_create(r) != NGX_OK) { |
603 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 612 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
604 } | 613 } |
605 | 614 |
638 u->output.tag = (ngx_buf_tag_t) &ngx_http_uwsgi_module; | 647 u->output.tag = (ngx_buf_tag_t) &ngx_http_uwsgi_module; |
639 | 648 |
640 u->conf = &uwcf->upstream; | 649 u->conf = &uwcf->upstream; |
641 | 650 |
642 #if (NGX_HTTP_CACHE) | 651 #if (NGX_HTTP_CACHE) |
652 uwmcf = ngx_http_get_module_main_conf(r, ngx_http_uwsgi_module); | |
653 | |
654 u->caches = &uwmcf->caches; | |
643 u->create_key = ngx_http_uwsgi_create_key; | 655 u->create_key = ngx_http_uwsgi_create_key; |
644 #endif | 656 #endif |
657 | |
645 u->create_request = ngx_http_uwsgi_create_request; | 658 u->create_request = ngx_http_uwsgi_create_request; |
646 u->reinit_request = ngx_http_uwsgi_reinit_request; | 659 u->reinit_request = ngx_http_uwsgi_reinit_request; |
647 u->process_header = ngx_http_uwsgi_process_status_line; | 660 u->process_header = ngx_http_uwsgi_process_status_line; |
648 u->abort_request = ngx_http_uwsgi_abort_request; | 661 u->abort_request = ngx_http_uwsgi_abort_request; |
649 u->finalize_request = ngx_http_uwsgi_finalize_request; | 662 u->finalize_request = ngx_http_uwsgi_finalize_request; |
1314 return; | 1327 return; |
1315 } | 1328 } |
1316 | 1329 |
1317 | 1330 |
1318 static void * | 1331 static void * |
1332 ngx_http_uwsgi_create_main_conf(ngx_conf_t *cf) | |
1333 { | |
1334 ngx_http_uwsgi_main_conf_t *conf; | |
1335 | |
1336 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uwsgi_main_conf_t)); | |
1337 if (conf == NULL) { | |
1338 return NULL; | |
1339 } | |
1340 | |
1341 #if (NGX_HTTP_CACHE) | |
1342 if (ngx_array_init(&conf->caches, cf->pool, 4, | |
1343 sizeof(ngx_http_file_cache_t *)) | |
1344 != NGX_OK) | |
1345 { | |
1346 return NULL; | |
1347 } | |
1348 #endif | |
1349 | |
1350 return conf; | |
1351 } | |
1352 | |
1353 | |
1354 static void * | |
1319 ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf) | 1355 ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf) |
1320 { | 1356 { |
1321 ngx_http_uwsgi_loc_conf_t *conf; | 1357 ngx_http_uwsgi_loc_conf_t *conf; |
1322 | 1358 |
1323 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uwsgi_loc_conf_t)); | 1359 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uwsgi_loc_conf_t)); |
1581 if (conf->upstream.cache == NGX_CONF_UNSET) { | 1617 if (conf->upstream.cache == NGX_CONF_UNSET) { |
1582 ngx_conf_merge_value(conf->upstream.cache, | 1618 ngx_conf_merge_value(conf->upstream.cache, |
1583 prev->upstream.cache, 0); | 1619 prev->upstream.cache, 0); |
1584 | 1620 |
1585 conf->upstream.cache_zone = prev->upstream.cache_zone; | 1621 conf->upstream.cache_zone = prev->upstream.cache_zone; |
1622 conf->upstream.cache_value = prev->upstream.cache_value; | |
1586 } | 1623 } |
1587 | 1624 |
1588 if (conf->upstream.cache_zone && conf->upstream.cache_zone->data == NULL) { | 1625 if (conf->upstream.cache_zone && conf->upstream.cache_zone->data == NULL) { |
1589 ngx_shm_zone_t *shm_zone; | 1626 ngx_shm_zone_t *shm_zone; |
1590 | 1627 |
2112 static char * | 2149 static char * |
2113 ngx_http_uwsgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 2150 ngx_http_uwsgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2114 { | 2151 { |
2115 ngx_http_uwsgi_loc_conf_t *uwcf = conf; | 2152 ngx_http_uwsgi_loc_conf_t *uwcf = conf; |
2116 | 2153 |
2117 ngx_str_t *value; | 2154 ngx_str_t *value; |
2155 ngx_http_complex_value_t cv; | |
2156 ngx_http_compile_complex_value_t ccv; | |
2118 | 2157 |
2119 value = cf->args->elts; | 2158 value = cf->args->elts; |
2120 | 2159 |
2121 if (uwcf->upstream.cache != NGX_CONF_UNSET) { | 2160 if (uwcf->upstream.cache != NGX_CONF_UNSET) { |
2122 return "is duplicate"; | 2161 return "is duplicate"; |
2130 if (uwcf->upstream.store > 0) { | 2169 if (uwcf->upstream.store > 0) { |
2131 return "is incompatible with \"uwsgi_store\""; | 2170 return "is incompatible with \"uwsgi_store\""; |
2132 } | 2171 } |
2133 | 2172 |
2134 uwcf->upstream.cache = 1; | 2173 uwcf->upstream.cache = 1; |
2174 | |
2175 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
2176 | |
2177 ccv.cf = cf; | |
2178 ccv.value = &value[1]; | |
2179 ccv.complex_value = &cv; | |
2180 | |
2181 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
2182 return NGX_CONF_ERROR; | |
2183 } | |
2184 | |
2185 if (cv.lengths != NULL) { | |
2186 | |
2187 uwcf->upstream.cache_value = ngx_palloc(cf->pool, | |
2188 sizeof(ngx_http_complex_value_t)); | |
2189 if (uwcf->upstream.cache_value == NULL) { | |
2190 return NGX_CONF_ERROR; | |
2191 } | |
2192 | |
2193 *uwcf->upstream.cache_value = cv; | |
2194 | |
2195 return NGX_CONF_OK; | |
2196 } | |
2135 | 2197 |
2136 uwcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0, | 2198 uwcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0, |
2137 &ngx_http_uwsgi_module); | 2199 &ngx_http_uwsgi_module); |
2138 if (uwcf->upstream.cache_zone == NULL) { | 2200 if (uwcf->upstream.cache_zone == NULL) { |
2139 return NGX_CONF_ERROR; | 2201 return NGX_CONF_ERROR; |