Router: grouped app and share fields in nxt_http_action_t.

This is a prerequisite for further introduction of openat2() features.
No functional changes.
This commit is contained in:
Zhidao HONG
2021-04-22 13:13:06 +08:00
parent f90754f84a
commit 113afb09ea
5 changed files with 46 additions and 32 deletions

View File

@@ -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;
};

View File

@@ -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;
}

View File

@@ -626,16 +626,16 @@ static nxt_conf_map_t nxt_http_route_action_conf[] = {
NXT_CONF_MAP_STR,
offsetof(nxt_http_route_action_conf_t, location)
},
{
nxt_string("share"),
NXT_CONF_MAP_PTR,
offsetof(nxt_http_route_action_conf_t, share)
},
{
nxt_string("proxy"),
NXT_CONF_MAP_PTR,
offsetof(nxt_http_route_action_conf_t, proxy)
},
{
nxt_string("share"),
NXT_CONF_MAP_PTR,
offsetof(nxt_http_route_action_conf_t, share)
},
{
nxt_string("fallback"),
NXT_CONF_MAP_PTR,
@@ -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;
}

View File

@@ -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",

View File

@@ -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;