Mercurial > hg > nginx
comparison src/http/modules/ngx_http_scgi_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 |
---|---|
7 | 7 |
8 | 8 |
9 #include <ngx_config.h> | 9 #include <ngx_config.h> |
10 #include <ngx_core.h> | 10 #include <ngx_core.h> |
11 #include <ngx_http.h> | 11 #include <ngx_http.h> |
12 | |
13 | |
14 typedef struct { | |
15 ngx_array_t caches; /* ngx_http_file_cache_t * */ | |
16 } ngx_http_scgi_main_conf_t; | |
12 | 17 |
13 | 18 |
14 typedef struct { | 19 typedef struct { |
15 ngx_array_t *flushes; | 20 ngx_array_t *flushes; |
16 ngx_array_t *lengths; | 21 ngx_array_t *lengths; |
45 static ngx_int_t ngx_http_scgi_process_status_line(ngx_http_request_t *r); | 50 static ngx_int_t ngx_http_scgi_process_status_line(ngx_http_request_t *r); |
46 static ngx_int_t ngx_http_scgi_process_header(ngx_http_request_t *r); | 51 static ngx_int_t ngx_http_scgi_process_header(ngx_http_request_t *r); |
47 static void ngx_http_scgi_abort_request(ngx_http_request_t *r); | 52 static void ngx_http_scgi_abort_request(ngx_http_request_t *r); |
48 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc); | 53 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc); |
49 | 54 |
55 static void *ngx_http_scgi_create_main_conf(ngx_conf_t *cf); | |
50 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); | 56 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); |
51 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, | 57 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, |
52 void *child); | 58 void *child); |
53 static ngx_int_t ngx_http_scgi_init_params(ngx_conf_t *cf, | 59 static ngx_int_t ngx_http_scgi_init_params(ngx_conf_t *cf, |
54 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_params_t *params, | 60 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_params_t *params, |
222 NULL }, | 228 NULL }, |
223 | 229 |
224 { ngx_string("scgi_cache_path"), | 230 { ngx_string("scgi_cache_path"), |
225 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, | 231 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, |
226 ngx_http_file_cache_set_slot, | 232 ngx_http_file_cache_set_slot, |
227 0, | 233 NGX_HTTP_MAIN_CONF_OFFSET, |
228 0, | 234 offsetof(ngx_http_scgi_main_conf_t, caches), |
229 &ngx_http_scgi_module }, | 235 &ngx_http_scgi_module }, |
230 | 236 |
231 { ngx_string("scgi_cache_bypass"), | 237 { ngx_string("scgi_cache_bypass"), |
232 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | 238 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
233 ngx_http_set_predicate_slot, | 239 ngx_http_set_predicate_slot, |
376 | 382 |
377 static ngx_http_module_t ngx_http_scgi_module_ctx = { | 383 static ngx_http_module_t ngx_http_scgi_module_ctx = { |
378 NULL, /* preconfiguration */ | 384 NULL, /* preconfiguration */ |
379 NULL, /* postconfiguration */ | 385 NULL, /* postconfiguration */ |
380 | 386 |
381 NULL, /* create main configuration */ | 387 ngx_http_scgi_create_main_conf, /* create main configuration */ |
382 NULL, /* init main configuration */ | 388 NULL, /* init main configuration */ |
383 | 389 |
384 NULL, /* create server configuration */ | 390 NULL, /* create server configuration */ |
385 NULL, /* merge server configuration */ | 391 NULL, /* merge server configuration */ |
386 | 392 |
438 | 444 |
439 | 445 |
440 static ngx_int_t | 446 static ngx_int_t |
441 ngx_http_scgi_handler(ngx_http_request_t *r) | 447 ngx_http_scgi_handler(ngx_http_request_t *r) |
442 { | 448 { |
443 ngx_int_t rc; | 449 ngx_int_t rc; |
444 ngx_http_status_t *status; | 450 ngx_http_status_t *status; |
445 ngx_http_upstream_t *u; | 451 ngx_http_upstream_t *u; |
446 ngx_http_scgi_loc_conf_t *scf; | 452 ngx_http_scgi_loc_conf_t *scf; |
453 #if (NGX_HTTP_CACHE) | |
454 ngx_http_scgi_main_conf_t *smcf; | |
455 #endif | |
447 | 456 |
448 if (ngx_http_upstream_create(r) != NGX_OK) { | 457 if (ngx_http_upstream_create(r) != NGX_OK) { |
449 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 458 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
450 } | 459 } |
451 | 460 |
470 u->output.tag = (ngx_buf_tag_t) &ngx_http_scgi_module; | 479 u->output.tag = (ngx_buf_tag_t) &ngx_http_scgi_module; |
471 | 480 |
472 u->conf = &scf->upstream; | 481 u->conf = &scf->upstream; |
473 | 482 |
474 #if (NGX_HTTP_CACHE) | 483 #if (NGX_HTTP_CACHE) |
484 smcf = ngx_http_get_module_main_conf(r, ngx_http_scgi_module); | |
485 | |
486 u->caches = &smcf->caches; | |
475 u->create_key = ngx_http_scgi_create_key; | 487 u->create_key = ngx_http_scgi_create_key; |
476 #endif | 488 #endif |
489 | |
477 u->create_request = ngx_http_scgi_create_request; | 490 u->create_request = ngx_http_scgi_create_request; |
478 u->reinit_request = ngx_http_scgi_reinit_request; | 491 u->reinit_request = ngx_http_scgi_reinit_request; |
479 u->process_header = ngx_http_scgi_process_status_line; | 492 u->process_header = ngx_http_scgi_process_status_line; |
480 u->abort_request = ngx_http_scgi_abort_request; | 493 u->abort_request = ngx_http_scgi_abort_request; |
481 u->finalize_request = ngx_http_scgi_finalize_request; | 494 u->finalize_request = ngx_http_scgi_finalize_request; |
1111 return; | 1124 return; |
1112 } | 1125 } |
1113 | 1126 |
1114 | 1127 |
1115 static void * | 1128 static void * |
1129 ngx_http_scgi_create_main_conf(ngx_conf_t *cf) | |
1130 { | |
1131 ngx_http_scgi_main_conf_t *conf; | |
1132 | |
1133 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_scgi_main_conf_t)); | |
1134 if (conf == NULL) { | |
1135 return NULL; | |
1136 } | |
1137 | |
1138 #if (NGX_HTTP_CACHE) | |
1139 if (ngx_array_init(&conf->caches, cf->pool, 4, | |
1140 sizeof(ngx_http_file_cache_t *)) | |
1141 != NGX_OK) | |
1142 { | |
1143 return NULL; | |
1144 } | |
1145 #endif | |
1146 | |
1147 return conf; | |
1148 } | |
1149 | |
1150 | |
1151 static void * | |
1116 ngx_http_scgi_create_loc_conf(ngx_conf_t *cf) | 1152 ngx_http_scgi_create_loc_conf(ngx_conf_t *cf) |
1117 { | 1153 { |
1118 ngx_http_scgi_loc_conf_t *conf; | 1154 ngx_http_scgi_loc_conf_t *conf; |
1119 | 1155 |
1120 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_scgi_loc_conf_t)); | 1156 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_scgi_loc_conf_t)); |
1367 if (conf->upstream.cache == NGX_CONF_UNSET) { | 1403 if (conf->upstream.cache == NGX_CONF_UNSET) { |
1368 ngx_conf_merge_value(conf->upstream.cache, | 1404 ngx_conf_merge_value(conf->upstream.cache, |
1369 prev->upstream.cache, 0); | 1405 prev->upstream.cache, 0); |
1370 | 1406 |
1371 conf->upstream.cache_zone = prev->upstream.cache_zone; | 1407 conf->upstream.cache_zone = prev->upstream.cache_zone; |
1408 conf->upstream.cache_value = prev->upstream.cache_value; | |
1372 } | 1409 } |
1373 | 1410 |
1374 if (conf->upstream.cache_zone && conf->upstream.cache_zone->data == NULL) { | 1411 if (conf->upstream.cache_zone && conf->upstream.cache_zone->data == NULL) { |
1375 ngx_shm_zone_t *shm_zone; | 1412 ngx_shm_zone_t *shm_zone; |
1376 | 1413 |
1823 static char * | 1860 static char * |
1824 ngx_http_scgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1861 ngx_http_scgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1825 { | 1862 { |
1826 ngx_http_scgi_loc_conf_t *scf = conf; | 1863 ngx_http_scgi_loc_conf_t *scf = conf; |
1827 | 1864 |
1828 ngx_str_t *value; | 1865 ngx_str_t *value; |
1866 ngx_http_complex_value_t cv; | |
1867 ngx_http_compile_complex_value_t ccv; | |
1829 | 1868 |
1830 value = cf->args->elts; | 1869 value = cf->args->elts; |
1831 | 1870 |
1832 if (scf->upstream.cache != NGX_CONF_UNSET) { | 1871 if (scf->upstream.cache != NGX_CONF_UNSET) { |
1833 return "is duplicate"; | 1872 return "is duplicate"; |
1841 if (scf->upstream.store > 0) { | 1880 if (scf->upstream.store > 0) { |
1842 return "is incompatible with \"scgi_store\""; | 1881 return "is incompatible with \"scgi_store\""; |
1843 } | 1882 } |
1844 | 1883 |
1845 scf->upstream.cache = 1; | 1884 scf->upstream.cache = 1; |
1885 | |
1886 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
1887 | |
1888 ccv.cf = cf; | |
1889 ccv.value = &value[1]; | |
1890 ccv.complex_value = &cv; | |
1891 | |
1892 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
1893 return NGX_CONF_ERROR; | |
1894 } | |
1895 | |
1896 if (cv.lengths != NULL) { | |
1897 | |
1898 scf->upstream.cache_value = ngx_palloc(cf->pool, | |
1899 sizeof(ngx_http_complex_value_t)); | |
1900 if (scf->upstream.cache_value == NULL) { | |
1901 return NGX_CONF_ERROR; | |
1902 } | |
1903 | |
1904 *scf->upstream.cache_value = cv; | |
1905 | |
1906 return NGX_CONF_OK; | |
1907 } | |
1846 | 1908 |
1847 scf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0, | 1909 scf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0, |
1848 &ngx_http_scgi_module); | 1910 &ngx_http_scgi_module); |
1849 if (scf->upstream.cache_zone == NULL) { | 1911 if (scf->upstream.cache_zone == NULL) { |
1850 return NGX_CONF_ERROR; | 1912 return NGX_CONF_ERROR; |