summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_route.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2020-05-14 13:15:01 +0300
committerValentin Bartenev <vbart@nginx.com>2020-05-14 13:15:01 +0300
commit376d758dd72ac27f2bd5bb833ba68f5c9b531880 (patch)
treea3891a0586669543c35004ccbff3a6deca893903 /src/nxt_http_route.c
parent0174c971b5ec0d604e4e9becfa41e0bc31179e57 (diff)
downloadunit-376d758dd72ac27f2bd5bb833ba68f5c9b531880.tar.gz
unit-376d758dd72ac27f2bd5bb833ba68f5c9b531880.tar.bz2
PHP: implemented "targets" option.
This allows to specify multiple subsequent targets inside PHP applications. For example: { "listeners": { "*:80": { "pass": "routes" } }, "routes": [ { "match": { "uri": "/info" }, "action": { "pass": "applications/my_app/phpinfo" } }, { "match": { "uri": "/hello" }, "action": { "pass": "applications/my_app/hello" } }, { "action": { "pass": "applications/my_app/rest" } } ], "applications": { "my_app": { "type": "php", "targets": { "phpinfo": { "script": "phpinfo.php", "root": "/www/data/admin", }, "hello": { "script": "hello.php", "root": "/www/data/test", }, "rest": { "root": "/www/data/example.com", "index": "index.php" }, } } } }
Diffstat (limited to '')
-rw-r--r--src/nxt_http_route.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index bb6e9dc9..06bc91da 100644
--- a/src/nxt_http_route.c
+++ b/src/nxt_http_route.c
@@ -1151,8 +1151,10 @@ static nxt_int_t
nxt_http_action_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
nxt_http_action_t *action)
{
- nxt_int_t ret;
- nxt_str_t segments[2];
+ nxt_str_t *targets;
+ nxt_int_t ret;
+ nxt_uint_t i;
+ nxt_str_t segments[3];
if (action->handler != NULL) {
if (action->handler == nxt_http_static_handler
@@ -1164,7 +1166,7 @@ nxt_http_action_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
return NXT_OK;
}
- ret = nxt_http_pass_segments(tmcf->mem_pool, &action->name, segments, 2);
+ ret = nxt_http_pass_segments(tmcf->mem_pool, &action->name, segments, 3);
if (nxt_slow_path(ret != NXT_OK)) {
return NXT_ERROR;
}
@@ -1173,6 +1175,17 @@ nxt_http_action_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
nxt_router_listener_application(tmcf, &segments[1], action);
nxt_router_app_use(task, action->u.application, 1);
+ if (segments[2].length != 0) {
+ targets = action->u.application->targets;
+
+ for (i = 0; !nxt_strstr_eq(&segments[2], &targets[i]); i++);
+
+ action->target = i;
+
+ } else {
+ action->target = 0;
+ }
+
} else if (nxt_str_eq(&segments[0], "upstreams", 9)) {
nxt_upstream_find(tmcf->router_conf->upstreams, &segments[1], action);
@@ -1298,6 +1311,8 @@ nxt_http_pass_application(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
nxt_router_listener_application(tmcf, name, action);
nxt_router_app_use(task, action->u.application, 1);
+ action->target = 0;
+
return action;
}