[nginx] svn commit: r4464 - trunk/src/http/modules
vbart at nginx.com
vbart at nginx.com
Mon Feb 13 11:00:09 UTC 2012
Author: vbart
Date: 2012-02-13 11:00:08 +0000 (Mon, 13 Feb 2012)
New Revision: 4464
Modified:
trunk/src/http/modules/ngx_http_proxy_module.c
Log:
Proxy: generic regex related code from the "proxy_redirect" directive moved
to a separate function.
No functional changes.
Modified: trunk/src/http/modules/ngx_http_proxy_module.c
===================================================================
--- trunk/src/http/modules/ngx_http_proxy_module.c 2012-02-13 10:56:09 UTC (rev 4463)
+++ trunk/src/http/modules/ngx_http_proxy_module.c 2012-02-13 11:00:08 UTC (rev 4464)
@@ -149,6 +149,9 @@
static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data);
+static ngx_int_t ngx_http_proxy_rewrite_regex(ngx_conf_t *cf,
+ ngx_http_proxy_rewrite_t *pr, ngx_str_t *regex, ngx_uint_t caseless);
+
#if (NGX_HTTP_SSL)
static ngx_int_t ngx_http_proxy_set_ssl(ngx_conf_t *cf,
ngx_http_proxy_loc_conf_t *plcf);
@@ -3385,39 +3388,23 @@
if (value[1].data[0] == '~') {
-#if (NGX_PCRE)
- u_char errstr[NGX_MAX_CONF_ERRSTR];
- ngx_regex_compile_t rc;
-
value[1].len--;
value[1].data++;
- ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
-
if (value[1].data[0] == '*') {
value[1].len--;
value[1].data++;
- rc.options = NGX_REGEX_CASELESS;
- }
- rc.pattern = value[1];
- rc.err.len = NGX_MAX_CONF_ERRSTR;
- rc.err.data = errstr;
+ if (ngx_http_proxy_rewrite_regex(cf, pr, &value[1], 1) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
- pr->pattern.regex = ngx_http_regex_compile(cf, &rc);
- if (pr->pattern.regex == NULL) {
- return NGX_CONF_ERROR;
+ } else {
+ if (ngx_http_proxy_rewrite_regex(cf, pr, &value[1], 0) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
}
- pr->handler = ngx_http_proxy_rewrite_regex_handler;
-
-#else
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "using regex \"%V\" requires PCRE library",
- &value[1]);
-
- return NGX_CONF_ERROR;
-#endif
} else {
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
@@ -3448,6 +3435,43 @@
}
+static ngx_int_t
+ngx_http_proxy_rewrite_regex(ngx_conf_t *cf, ngx_http_proxy_rewrite_t *pr,
+ ngx_str_t *regex, ngx_uint_t caseless)
+{
+#if (NGX_PCRE)
+ u_char errstr[NGX_MAX_CONF_ERRSTR];
+ ngx_regex_compile_t rc;
+
+ ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
+
+ rc.pattern = *regex;
+ rc.err.len = NGX_MAX_CONF_ERRSTR;
+ rc.err.data = errstr;
+
+ if (caseless) {
+ rc.options = NGX_REGEX_CASELESS;
+ }
+
+ pr->pattern.regex = ngx_http_regex_compile(cf, &rc);
+ if (pr->pattern.regex == NULL) {
+ return NGX_ERROR;
+ }
+
+ pr->handler = ngx_http_proxy_rewrite_regex_handler;
+
+ return NGX_OK;
+
+#else
+
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "using regex \"%V\" requires PCRE library", regex);
+ return NGX_ERROR;
+
+#endif
+}
+
+
static char *
ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
More information about the nginx-devel
mailing list