summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2021-04-22 13:13:06 +0800
committerZhidao HONG <z.hong@f5.com>2021-04-22 13:13:06 +0800
commit113afb09ea7ddeebf2376cf6df3af212705e6128 (patch)
treed39074cf006ed99d03ee97503d70f8981405deec
parentf90754f84a375d5183ed6883862d19dfd417225a (diff)
downloadunit-113afb09ea7ddeebf2376cf6df3af212705e6128.tar.gz
unit-113afb09ea7ddeebf2376cf6df3af212705e6128.tar.bz2
Router: grouped app and share fields in nxt_http_action_t.
This is a prerequisite for further introduction of openat2() features. No functional changes.
-rw-r--r--src/nxt_http.h12
-rw-r--r--src/nxt_http_request.c4
-rw-r--r--src/nxt_http_route.c46
-rw-r--r--src/nxt_http_static.c12
-rw-r--r--src/nxt_router.c2
5 files changed, 45 insertions, 31 deletions
diff --git a/src/nxt_http.h b/src/nxt_http.h
index e30bfeb4..2aa108ec 100644
--- a/src/nxt_http.h
+++ b/src/nxt_http.h
@@ -206,16 +206,22 @@ struct nxt_http_action_s {
nxt_http_action_t *action);
union {
nxt_http_route_t *route;
- nxt_app_t *application;
- nxt_http_action_t *fallback;
nxt_upstream_t *upstream;
uint32_t upstream_number;
nxt_http_status_t return_code;
nxt_var_t *var;
+
+ struct {
+ nxt_app_t *application;
+ nxt_int_t target;
+ } app;
+
+ struct {
+ nxt_http_action_t *fallback;
+ } share;
} u;
nxt_str_t name;
- nxt_int_t target;
};
diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c
index 650c1a89..779cfcf8 100644
--- a/src/nxt_http_request.c
+++ b/src/nxt_http_request.c
@@ -348,9 +348,9 @@ nxt_http_application_handler(nxt_task_t *task, nxt_http_request_t *r,
nxt_str_set(&r->server_name, "localhost");
}
- r->app_target = action->target;
+ r->app_target = action->u.app.target;
- nxt_router_process_http_request(task, r, action->u.application);
+ nxt_router_process_http_request(task, r, action->u.app.application);
return NULL;
}
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index 28545fc9..dfdb07df 100644
--- a/src/nxt_http_route.c
+++ b/src/nxt_http_route.c
@@ -627,14 +627,14 @@ static nxt_conf_map_t nxt_http_route_action_conf[] = {
offsetof(nxt_http_route_action_conf_t, location)
},
{
- nxt_string("share"),
+ nxt_string("proxy"),
NXT_CONF_MAP_PTR,
- offsetof(nxt_http_route_action_conf_t, share)
+ offsetof(nxt_http_route_action_conf_t, proxy)
},
{
- nxt_string("proxy"),
+ nxt_string("share"),
NXT_CONF_MAP_PTR,
- offsetof(nxt_http_route_action_conf_t, proxy)
+ offsetof(nxt_http_route_action_conf_t, share)
},
{
nxt_string("fallback"),
@@ -700,14 +700,14 @@ nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv,
return NXT_OK;
}
- conf = accf.pass;
-
if (accf.share != NULL) {
conf = accf.share;
- action->handler = nxt_http_static_handler;
} else if (accf.proxy != NULL) {
conf = accf.proxy;
+
+ } else {
+ conf = accf.pass;
}
nxt_conf_get_string(conf, &name);
@@ -717,14 +717,21 @@ nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv,
return NXT_ERROR;
}
- if (accf.fallback != NULL) {
- action->u.fallback = nxt_mp_alloc(mp, sizeof(nxt_http_action_t));
- if (nxt_slow_path(action->u.fallback == NULL)) {
- return NXT_ERROR;
+ if (accf.share != NULL) {
+ action->handler = nxt_http_static_handler;
+
+ if (accf.fallback != NULL) {
+ action->u.share.fallback = nxt_mp_alloc(mp,
+ sizeof(nxt_http_action_t));
+ if (nxt_slow_path(action->u.share.fallback == NULL)) {
+ return NXT_ERROR;
+ }
+
+ return nxt_http_route_action_create(tmcf, accf.fallback,
+ action->u.share.fallback);
}
- return nxt_http_route_action_create(tmcf, accf.fallback,
- action->u.fallback);
+ return NXT_OK;
}
if (accf.proxy != NULL) {
@@ -1411,9 +1418,10 @@ nxt_http_action_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
if (action->handler != NULL) {
if (action->handler == nxt_http_static_handler
- && action->u.fallback != NULL)
+ && action->u.share.fallback != NULL)
{
- return nxt_http_action_resolve(task, tmcf, action->u.fallback);
+ return nxt_http_action_resolve(task, tmcf,
+ action->u.share.fallback);
}
return NXT_OK;
@@ -1533,14 +1541,14 @@ nxt_http_pass_find(nxt_task_t *task, nxt_mp_t *mp, nxt_router_conf_t *rtcf,
}
if (segments[2].length != 0) {
- targets = action->u.application->targets;
+ targets = action->u.app.application->targets;
for (i = 0; !nxt_strstr_eq(&segments[2], &targets[i]); i++);
- action->target = i;
+ action->u.app.target = i;
} else {
- action->target = 0;
+ action->u.app.target = 0;
}
return NXT_OK;
@@ -1678,7 +1686,7 @@ nxt_http_pass_application(nxt_task_t *task, nxt_router_conf_t *rtcf,
(void) nxt_router_listener_application(rtcf, name, action);
- action->target = 0;
+ action->u.app.target = 0;
return action;
}
diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index df2655fc..c0b48586 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -49,8 +49,8 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r,
if (nxt_slow_path(!nxt_str_eq(r->method, "GET", 3))) {
if (!nxt_str_eq(r->method, "HEAD", 4)) {
- if (action->u.fallback != NULL) {
- return action->u.fallback;
+ if (action->u.share.fallback != NULL) {
+ return action->u.share.fallback;
}
nxt_http_request_error(task, r, NXT_HTTP_METHOD_NOT_ALLOWED);
@@ -127,8 +127,8 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r,
break;
}
- if (level == NXT_LOG_ERR && action->u.fallback != NULL) {
- return action->u.fallback;
+ if (level == NXT_LOG_ERR && action->u.share.fallback != NULL) {
+ return action->u.share.fallback;
}
if (status != NXT_HTTP_NOT_FOUND) {
@@ -230,8 +230,8 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r,
nxt_file_close(task, f);
if (nxt_slow_path(!nxt_is_dir(&fi))) {
- if (action->u.fallback != NULL) {
- return action->u.fallback;
+ if (action->u.share.fallback != NULL) {
+ return action->u.share.fallback;
}
nxt_log(task, NXT_LOG_ERR, "\"%FN\" is not a regular file",
diff --git a/src/nxt_router.c b/src/nxt_router.c
index 8524b358..a20e4ede 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -2144,7 +2144,7 @@ nxt_router_listener_application(nxt_router_conf_t *rtcf, nxt_str_t *name,
return NXT_DECLINED;
}
- action->u.application = app;
+ action->u.app.application = app;
action->handler = nxt_http_application_handler;
return NXT_OK;