aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http/ngx_http_core_module.c3
-rw-r--r--src/http/ngx_http_core_module.h1
-rw-r--r--src/http/ngx_http_request.c27
3 files changed, 30 insertions, 1 deletions
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index cd7159e08..ad009462e 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -2819,6 +2819,7 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
#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 @@ ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
#if (NGX_PCRE)
sn->regex = NULL;
+ sn->captures = 0;
#endif
sn->core_srv_conf = cscf;
sn->name = value[i];
@@ -3446,6 +3448,7 @@ ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
+ sn->captures = (ngx_regex_capture_count(sn->regex) > 0);
sn->name = value[i];
}
#else
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 0926b1091..7ad18edd2 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -245,6 +245,7 @@ typedef struct {
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;
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index faa8d7fa9..5a2a8f42c 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -1653,11 +1653,33 @@ ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len)
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 @@ ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len)
cscf = sn[i].core_srv_conf;
+ r->ncaptures = len;
+ r->captures_data = server;
+
goto found;
}
}