aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_rewrite_module.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/modules/ngx_http_rewrite_module.c')
-rw-r--r--src/http/modules/ngx_http_rewrite_module.c64
1 files changed, 17 insertions, 47 deletions
diff --git a/src/http/modules/ngx_http_rewrite_module.c b/src/http/modules/ngx_http_rewrite_module.c
index 1f98cf829..b07eedc78 100644
--- a/src/http/modules/ngx_http_rewrite_module.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -294,9 +294,9 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
- ngx_str_t *value, err;
- ngx_int_t n;
+ ngx_str_t *value;
ngx_uint_t last;
+ ngx_regex_compile_t rc;
ngx_http_script_code_pt *code;
ngx_http_script_compile_t sc;
ngx_http_script_regex_code_t *regex;
@@ -313,15 +313,16 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
value = cf->args->elts;
- err.len = NGX_MAX_CONF_ERRSTR;
- err.data = errstr;
+ ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
- /* TODO: NGX_REGEX_CASELESS */
+ rc.pattern = value[1];
+ rc.err.len = NGX_MAX_CONF_ERRSTR;
+ rc.err.data = errstr;
- regex->regex = ngx_regex_compile(&value[1], 0, cf->pool, &err);
+ /* TODO: NGX_REGEX_CASELESS */
+ regex->regex = ngx_http_regex_compile(cf, &rc);
if (regex->regex == NULL) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
return NGX_CONF_ERROR;
}
@@ -394,7 +395,6 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
regex = sc.main;
- regex->ncaptures = sc.ncaptures;
regex->size = sc.size;
regex->args = sc.args;
@@ -402,31 +402,6 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
regex->lengths = NULL;
}
- n = ngx_regex_capture_count(regex->regex);
-
- if (n < 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- ngx_regex_capture_count_n " failed for "
- "pattern \"%V\"", &value[1]);
- return NGX_CONF_ERROR;
- }
-
- if (regex->ncaptures > (ngx_uint_t) n) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "pattern \"%V\" has less captures "
- "than referrenced in substitution \"%V\"",
- &value[1], &value[2]);
- return NGX_CONF_ERROR;
- }
-
- if (regex->ncaptures < (ngx_uint_t) n) {
- regex->ncaptures = (ngx_uint_t) n;
- }
-
- if (regex->ncaptures) {
- regex->ncaptures = (regex->ncaptures + 1) * 3;
- }
-
regex_end = ngx_http_script_add_code(lcf->codes,
sizeof(ngx_http_script_regex_end_code_t),
&regex);
@@ -624,8 +599,9 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
{
u_char *p;
size_t len;
- ngx_str_t *value, err;
- ngx_uint_t cur, last, n;
+ ngx_str_t *value;
+ ngx_uint_t cur, last;
+ ngx_regex_compile_t rc;
ngx_http_script_code_pt *code;
ngx_http_script_file_code_t *fop;
ngx_http_script_regex_code_t *regex;
@@ -733,15 +709,15 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
ngx_memzero(regex, sizeof(ngx_http_script_regex_code_t));
- err.len = NGX_MAX_CONF_ERRSTR;
- err.data = errstr;
+ ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
- regex->regex = ngx_regex_compile(&value[last],
- (p[len - 1] == '*') ? NGX_REGEX_CASELESS : 0,
- cf->pool, &err);
+ rc.pattern = value[last];
+ rc.options = (p[len - 1] == '*') ? NGX_REGEX_CASELESS : 0;
+ rc.err.len = NGX_MAX_CONF_ERRSTR;
+ rc.err.data = errstr;
+ regex->regex = ngx_http_regex_compile(cf, &rc);
if (regex->regex == NULL) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
return NGX_CONF_ERROR;
}
@@ -753,12 +729,6 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
}
regex->name = value[last];
- n = ngx_regex_capture_count(regex->regex);
-
- if (n) {
- regex->ncaptures = (n + 1) * 3;
- }
-
return NGX_CONF_OK;
}