Mercurial > hg > nginx-vendor-0-5
comparison src/http/modules/ngx_http_proxy_module.c @ 322:56675f002600 NGINX_0_5_31
nginx 0.5.31
*) Feature: named locations.
*) Feature: the "proxy_store" and "fastcgi_store" directives.
*) Feature: the "proxy_store_access" and "fastcgi_store_access"
directives.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 15 Aug 2007 00:00:00 +0400 |
parents | 95d92ec39071 |
children | 7cf404023f50 |
comparison
equal
deleted
inserted
replaced
321:6762c33c7da8 | 322:56675f002600 |
---|---|
103 | 103 |
104 static char *ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, | 104 static char *ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
105 void *conf); | 105 void *conf); |
106 static char *ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, | 106 static char *ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, |
107 void *conf); | 107 void *conf); |
108 static char *ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd, | |
109 void *conf); | |
108 | 110 |
109 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); | 111 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); |
110 | 112 |
111 static char *ngx_http_proxy_upstream_max_fails_unsupported(ngx_conf_t *cf, | 113 static char *ngx_http_proxy_upstream_max_fails_unsupported(ngx_conf_t *cf, |
112 ngx_command_t *cmd, void *conf); | 114 ngx_command_t *cmd, void *conf); |
150 { ngx_string("proxy_redirect"), | 152 { ngx_string("proxy_redirect"), |
151 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, | 153 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, |
152 ngx_http_proxy_redirect, | 154 ngx_http_proxy_redirect, |
153 NGX_HTTP_LOC_CONF_OFFSET, | 155 NGX_HTTP_LOC_CONF_OFFSET, |
154 0, | 156 0, |
157 NULL }, | |
158 | |
159 { ngx_string("proxy_store"), | |
160 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
161 ngx_http_proxy_store, | |
162 NGX_HTTP_LOC_CONF_OFFSET, | |
163 0, | |
164 NULL }, | |
165 | |
166 { ngx_string("proxy_store_access"), | |
167 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123, | |
168 ngx_conf_set_access_slot, | |
169 NGX_HTTP_LOC_CONF_OFFSET, | |
170 offsetof(ngx_http_proxy_loc_conf_t, upstream.store_access), | |
155 NULL }, | 171 NULL }, |
156 | 172 |
157 { ngx_string("proxy_buffering"), | 173 { ngx_string("proxy_buffering"), |
158 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 174 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
159 ngx_conf_set_flag_slot, | 175 ngx_conf_set_flag_slot, |
1488 * conf->upstream.hide_headers = NULL; | 1504 * conf->upstream.hide_headers = NULL; |
1489 * conf->upstream.pass_headers = NULL; | 1505 * conf->upstream.pass_headers = NULL; |
1490 * conf->upstream.schema = { 0, NULL }; | 1506 * conf->upstream.schema = { 0, NULL }; |
1491 * conf->upstream.uri = { 0, NULL }; | 1507 * conf->upstream.uri = { 0, NULL }; |
1492 * conf->upstream.location = NULL; | 1508 * conf->upstream.location = NULL; |
1509 * conf->upstream.store_lengths = NULL; | |
1510 * conf->upstream.store_values = NULL; | |
1493 * | 1511 * |
1494 * conf->method = NULL; | 1512 * conf->method = NULL; |
1495 * conf->headers_source = NULL; | 1513 * conf->headers_source = NULL; |
1496 * conf->headers_set_len = NULL; | 1514 * conf->headers_set_len = NULL; |
1497 * conf->headers_set = NULL; | 1515 * conf->headers_set = NULL; |
1500 * conf->body_set = NULL; | 1518 * conf->body_set = NULL; |
1501 * conf->body_source = { 0, NULL }; | 1519 * conf->body_source = { 0, NULL }; |
1502 * conf->rewrite_locations = NULL; | 1520 * conf->rewrite_locations = NULL; |
1503 */ | 1521 */ |
1504 | 1522 |
1523 conf->upstream.store = NGX_CONF_UNSET; | |
1524 conf->upstream.store_access = NGX_CONF_UNSET_UINT; | |
1505 conf->upstream.buffering = NGX_CONF_UNSET; | 1525 conf->upstream.buffering = NGX_CONF_UNSET; |
1506 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; | 1526 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; |
1507 | 1527 |
1508 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; | 1528 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
1509 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | 1529 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; |
1551 ngx_hash_init_t hash; | 1571 ngx_hash_init_t hash; |
1552 ngx_http_proxy_redirect_t *pr; | 1572 ngx_http_proxy_redirect_t *pr; |
1553 ngx_http_script_compile_t sc; | 1573 ngx_http_script_compile_t sc; |
1554 ngx_http_script_copy_code_t *copy; | 1574 ngx_http_script_copy_code_t *copy; |
1555 | 1575 |
1576 if (conf->upstream.store != 0) { | |
1577 ngx_conf_merge_value(conf->upstream.store, | |
1578 prev->upstream.store, 0); | |
1579 | |
1580 if (conf->upstream.store_lengths == NULL) { | |
1581 conf->upstream.store_lengths = prev->upstream.store_lengths; | |
1582 conf->upstream.store_values = prev->upstream.store_values; | |
1583 } | |
1584 } | |
1585 | |
1586 ngx_conf_merge_uint_value(conf->upstream.store_access, | |
1587 prev->upstream.store_access, 0600); | |
1588 | |
1556 ngx_conf_merge_value(conf->upstream.buffering, | 1589 ngx_conf_merge_value(conf->upstream.buffering, |
1557 prev->upstream.buffering, 1); | 1590 prev->upstream.buffering, 1); |
1558 | 1591 |
1559 ngx_conf_merge_value(conf->upstream.ignore_client_abort, | 1592 ngx_conf_merge_value(conf->upstream.ignore_client_abort, |
1560 prev->upstream.ignore_client_abort, 0); | 1593 prev->upstream.ignore_client_abort, 0); |
2240 | 2273 |
2241 clcf->handler = ngx_http_proxy_handler; | 2274 clcf->handler = ngx_http_proxy_handler; |
2242 | 2275 |
2243 plcf->upstream.location = clcf->name; | 2276 plcf->upstream.location = clcf->name; |
2244 | 2277 |
2278 if (clcf->named | |
2245 #if (NGX_PCRE) | 2279 #if (NGX_PCRE) |
2246 | 2280 || clcf->regex |
2247 if (clcf->regex || clcf->noname) { | 2281 #endif |
2282 || clcf->noname) | |
2283 { | |
2248 if (plcf->upstream.uri.len) { | 2284 if (plcf->upstream.uri.len) { |
2249 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 2285 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2250 "\"proxy_pass\" may not have URI part in " | 2286 "\"proxy_pass\" may not have URI part in " |
2251 "location given by regular expression, " | 2287 "location given by regular expression, " |
2288 "or inside named location, " | |
2252 "or inside the \"if\" statement, " | 2289 "or inside the \"if\" statement, " |
2253 "or inside the \"limit_except\" block"); | 2290 "or inside the \"limit_except\" block"); |
2254 return NGX_CONF_ERROR; | 2291 return NGX_CONF_ERROR; |
2255 } | 2292 } |
2256 | 2293 |
2257 plcf->upstream.location.len = 0; | 2294 plcf->upstream.location.len = 0; |
2258 } | 2295 } |
2259 | |
2260 #endif | |
2261 | 2296 |
2262 plcf->upstream.url = *url; | 2297 plcf->upstream.url = *url; |
2263 | 2298 |
2264 if (clcf->name.data[clcf->name.len - 1] == '/') { | 2299 if (clcf->name.data[clcf->name.len - 1] == '/') { |
2265 clcf->auto_redirect = 1; | 2300 clcf->auto_redirect = 1; |
2352 | 2387 |
2353 pr->handler = ngx_http_proxy_rewrite_redirect_vars; | 2388 pr->handler = ngx_http_proxy_rewrite_redirect_vars; |
2354 pr->redirect = value[1]; | 2389 pr->redirect = value[1]; |
2355 pr->replacement.vars.lengths = vars_lengths->elts; | 2390 pr->replacement.vars.lengths = vars_lengths->elts; |
2356 pr->replacement.vars.values = vars_values->elts; | 2391 pr->replacement.vars.values = vars_values->elts; |
2392 | |
2393 return NGX_CONF_OK; | |
2394 } | |
2395 | |
2396 | |
2397 static char * | |
2398 ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2399 { | |
2400 ngx_http_proxy_loc_conf_t *plcf = conf; | |
2401 | |
2402 ngx_str_t *value; | |
2403 ngx_http_script_compile_t sc; | |
2404 | |
2405 if (plcf->upstream.store != NGX_CONF_UNSET || plcf->upstream.store_lengths) | |
2406 { | |
2407 return "is duplicate"; | |
2408 } | |
2409 | |
2410 value = cf->args->elts; | |
2411 | |
2412 if (ngx_strcmp(value[1].data, "on") == 0) { | |
2413 plcf->upstream.store = 1; | |
2414 return NGX_CONF_OK; | |
2415 } | |
2416 | |
2417 if (ngx_strcmp(value[1].data, "off") == 0) { | |
2418 plcf->upstream.store = 0; | |
2419 return NGX_CONF_OK; | |
2420 } | |
2421 | |
2422 /* include the terminating '\0' into script */ | |
2423 value[1].len++; | |
2424 | |
2425 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2426 | |
2427 sc.cf = cf; | |
2428 sc.source = &value[1]; | |
2429 sc.lengths = &plcf->upstream.store_lengths; | |
2430 sc.values = &plcf->upstream.store_values; | |
2431 sc.variables = ngx_http_script_variables_count(&value[1]);; | |
2432 sc.complete_lengths = 1; | |
2433 sc.complete_values = 1; | |
2434 | |
2435 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2436 return NGX_CONF_ERROR; | |
2437 } | |
2357 | 2438 |
2358 return NGX_CONF_OK; | 2439 return NGX_CONF_OK; |
2359 } | 2440 } |
2360 | 2441 |
2361 | 2442 |