Mercurial > hg > nginx
changeset 2549:2d34fba7cf06
captures support in server_name
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 06 Mar 2009 12:50:20 +0000 |
parents | 163114282d2c |
children | 5e87ddb4764f |
files | src/http/ngx_http_core_module.c src/http/ngx_http_core_module.h src/http/ngx_http_request.c |
diffstat | 3 files changed, 30 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/http/ngx_http_core_module.c Fri Mar 06 12:49:22 2009 +0000 +++ b/src/http/ngx_http_core_module.c Fri Mar 06 12:50:20 2009 +0000 @@ -2819,6 +2819,7 @@ #if (NGX_PCRE) sn->regex = NULL; + sn->captures = 0; #endif sn->core_srv_conf = conf; sn->name.len = conf->server_name.len; @@ -3420,6 +3421,7 @@ #if (NGX_PCRE) sn->regex = NULL; + sn->captures = 0; #endif sn->core_srv_conf = cscf; sn->name = value[i]; @@ -3446,6 +3448,7 @@ return NGX_CONF_ERROR; } + sn->captures = (ngx_regex_capture_count(sn->regex) > 0); sn->name = value[i]; } #else
--- a/src/http/ngx_http_core_module.h Fri Mar 06 12:49:22 2009 +0000 +++ b/src/http/ngx_http_core_module.h Fri Mar 06 12:50:20 2009 +0000 @@ -245,6 +245,7 @@ struct ngx_http_server_name_s { #if (NGX_PCRE) ngx_regex_t *regex; + ngx_uint_t captures; /* unsigned captures:1; */ #endif ngx_http_core_srv_conf_t *core_srv_conf; /* virtual name server conf */ ngx_str_t name;
--- a/src/http/ngx_http_request.c Fri Mar 06 12:49:22 2009 +0000 +++ b/src/http/ngx_http_request.c Fri Mar 06 12:50:20 2009 +0000 @@ -1653,11 +1653,33 @@ name.len = len; name.data = server; + len = 0; + sn = vn->regex; for (i = 0; i < vn->nregex; i++) { - n = ngx_regex_exec(sn[i].regex, &name, NULL, 0); + if (sn[i].captures && r->captures == NULL) { + + len = (NGX_HTTP_MAX_CAPTURES + 1) * 3 * sizeof(int); + + r->captures = ngx_palloc(r->pool, len); + if (r->captures == NULL) { + return NGX_ERROR; + } + + if (server == buf) { + server = ngx_pnalloc(r->pool, len); + if (server == NULL) { + return NGX_ERROR; + } + + ngx_memcpy(server, buf, len); + name.data = server; + } + } + + n = ngx_regex_exec(sn[i].regex, &name, r->captures, len); if (n == NGX_REGEX_NO_MATCHED) { continue; @@ -1675,6 +1697,9 @@ cscf = sn[i].core_srv_conf; + r->ncaptures = len; + r->captures_data = server; + goto found; } }