Mercurial > hg > nginx
comparison src/http/modules/ngx_http_proxy_module.c @ 4463:a068ec122f17
Proxy: generic regex related code from the "proxy_redirect" directive moved
to a separate function.
No functional changes.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 13 Feb 2012 11:00:08 +0000 |
parents | a73c63bdce32 |
children | 8293fc2d802b |
comparison
equal
deleted
inserted
replaced
4462:a73c63bdce32 | 4463:a068ec122f17 |
---|---|
146 static char *ngx_http_proxy_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, | 146 static char *ngx_http_proxy_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, |
147 void *conf); | 147 void *conf); |
148 #endif | 148 #endif |
149 | 149 |
150 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); | 150 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); |
151 | |
152 static ngx_int_t ngx_http_proxy_rewrite_regex(ngx_conf_t *cf, | |
153 ngx_http_proxy_rewrite_t *pr, ngx_str_t *regex, ngx_uint_t caseless); | |
151 | 154 |
152 #if (NGX_HTTP_SSL) | 155 #if (NGX_HTTP_SSL) |
153 static ngx_int_t ngx_http_proxy_set_ssl(ngx_conf_t *cf, | 156 static ngx_int_t ngx_http_proxy_set_ssl(ngx_conf_t *cf, |
154 ngx_http_proxy_loc_conf_t *plcf); | 157 ngx_http_proxy_loc_conf_t *plcf); |
155 #endif | 158 #endif |
3383 return NGX_CONF_OK; | 3386 return NGX_CONF_OK; |
3384 } | 3387 } |
3385 | 3388 |
3386 | 3389 |
3387 if (value[1].data[0] == '~') { | 3390 if (value[1].data[0] == '~') { |
3388 #if (NGX_PCRE) | |
3389 u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
3390 ngx_regex_compile_t rc; | |
3391 | |
3392 value[1].len--; | 3391 value[1].len--; |
3393 value[1].data++; | 3392 value[1].data++; |
3394 | |
3395 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); | |
3396 | 3393 |
3397 if (value[1].data[0] == '*') { | 3394 if (value[1].data[0] == '*') { |
3398 value[1].len--; | 3395 value[1].len--; |
3399 value[1].data++; | 3396 value[1].data++; |
3400 rc.options = NGX_REGEX_CASELESS; | 3397 |
3401 } | 3398 if (ngx_http_proxy_rewrite_regex(cf, pr, &value[1], 1) != NGX_OK) { |
3402 | 3399 return NGX_CONF_ERROR; |
3403 rc.pattern = value[1]; | 3400 } |
3404 rc.err.len = NGX_MAX_CONF_ERRSTR; | 3401 |
3405 rc.err.data = errstr; | 3402 } else { |
3406 | 3403 if (ngx_http_proxy_rewrite_regex(cf, pr, &value[1], 0) != NGX_OK) { |
3407 pr->pattern.regex = ngx_http_regex_compile(cf, &rc); | 3404 return NGX_CONF_ERROR; |
3408 if (pr->pattern.regex == NULL) { | 3405 } |
3409 return NGX_CONF_ERROR; | 3406 } |
3410 } | 3407 |
3411 | |
3412 pr->handler = ngx_http_proxy_rewrite_regex_handler; | |
3413 | |
3414 #else | |
3415 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3416 "using regex \"%V\" requires PCRE library", | |
3417 &value[1]); | |
3418 | |
3419 return NGX_CONF_ERROR; | |
3420 #endif | |
3421 } else { | 3408 } else { |
3422 | 3409 |
3423 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | 3410 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
3424 | 3411 |
3425 ccv.cf = cf; | 3412 ccv.cf = cf; |
3443 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | 3430 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
3444 return NGX_CONF_ERROR; | 3431 return NGX_CONF_ERROR; |
3445 } | 3432 } |
3446 | 3433 |
3447 return NGX_CONF_OK; | 3434 return NGX_CONF_OK; |
3435 } | |
3436 | |
3437 | |
3438 static ngx_int_t | |
3439 ngx_http_proxy_rewrite_regex(ngx_conf_t *cf, ngx_http_proxy_rewrite_t *pr, | |
3440 ngx_str_t *regex, ngx_uint_t caseless) | |
3441 { | |
3442 #if (NGX_PCRE) | |
3443 u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
3444 ngx_regex_compile_t rc; | |
3445 | |
3446 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); | |
3447 | |
3448 rc.pattern = *regex; | |
3449 rc.err.len = NGX_MAX_CONF_ERRSTR; | |
3450 rc.err.data = errstr; | |
3451 | |
3452 if (caseless) { | |
3453 rc.options = NGX_REGEX_CASELESS; | |
3454 } | |
3455 | |
3456 pr->pattern.regex = ngx_http_regex_compile(cf, &rc); | |
3457 if (pr->pattern.regex == NULL) { | |
3458 return NGX_ERROR; | |
3459 } | |
3460 | |
3461 pr->handler = ngx_http_proxy_rewrite_regex_handler; | |
3462 | |
3463 return NGX_OK; | |
3464 | |
3465 #else | |
3466 | |
3467 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3468 "using regex \"%V\" requires PCRE library", regex); | |
3469 return NGX_ERROR; | |
3470 | |
3471 #endif | |
3448 } | 3472 } |
3449 | 3473 |
3450 | 3474 |
3451 static char * | 3475 static char * |
3452 ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3476 ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |