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); nxt_http_action_t *action);
union { union {
nxt_http_route_t *route; nxt_http_route_t *route;
nxt_app_t *application;
nxt_http_action_t *fallback;
nxt_upstream_t *upstream; nxt_upstream_t *upstream;
uint32_t upstream_number; uint32_t upstream_number;
nxt_http_status_t return_code; nxt_http_status_t return_code;
nxt_var_t *var; nxt_var_t *var;
struct {
nxt_app_t *application;
nxt_int_t target;
} app;
struct {
nxt_http_action_t *fallback;
} share;
} u; } u;
nxt_str_t name; 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"); 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; return NULL;
} }

View File

@@ -626,16 +626,16 @@ static nxt_conf_map_t nxt_http_route_action_conf[] = {
NXT_CONF_MAP_STR, NXT_CONF_MAP_STR,
offsetof(nxt_http_route_action_conf_t, location) 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_string("proxy"),
NXT_CONF_MAP_PTR, NXT_CONF_MAP_PTR,
offsetof(nxt_http_route_action_conf_t, proxy) 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_string("fallback"),
NXT_CONF_MAP_PTR, 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; return NXT_OK;
} }
conf = accf.pass;
if (accf.share != NULL) { if (accf.share != NULL) {
conf = accf.share; conf = accf.share;
action->handler = nxt_http_static_handler;
} else if (accf.proxy != NULL) { } else if (accf.proxy != NULL) {
conf = accf.proxy; conf = accf.proxy;
} else {
conf = accf.pass;
} }
nxt_conf_get_string(conf, &name); 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; return NXT_ERROR;
} }
if (accf.share != NULL) {
action->handler = nxt_http_static_handler;
if (accf.fallback != NULL) { if (accf.fallback != NULL) {
action->u.fallback = nxt_mp_alloc(mp, sizeof(nxt_http_action_t)); action->u.share.fallback = nxt_mp_alloc(mp,
if (nxt_slow_path(action->u.fallback == NULL)) { sizeof(nxt_http_action_t));
if (nxt_slow_path(action->u.share.fallback == NULL)) {
return NXT_ERROR; return NXT_ERROR;
} }
return nxt_http_route_action_create(tmcf, accf.fallback, return nxt_http_route_action_create(tmcf, accf.fallback,
action->u.fallback); action->u.share.fallback);
}
return NXT_OK;
} }
if (accf.proxy != NULL) { 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 != NULL) {
if (action->handler == nxt_http_static_handler 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; 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) { 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++); for (i = 0; !nxt_strstr_eq(&segments[2], &targets[i]); i++);
action->target = i; action->u.app.target = i;
} else { } else {
action->target = 0; action->u.app.target = 0;
} }
return NXT_OK; 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); (void) nxt_router_listener_application(rtcf, name, action);
action->target = 0; action->u.app.target = 0;
return action; 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_slow_path(!nxt_str_eq(r->method, "GET", 3))) {
if (!nxt_str_eq(r->method, "HEAD", 4)) { if (!nxt_str_eq(r->method, "HEAD", 4)) {
if (action->u.fallback != NULL) { if (action->u.share.fallback != NULL) {
return action->u.fallback; return action->u.share.fallback;
} }
nxt_http_request_error(task, r, NXT_HTTP_METHOD_NOT_ALLOWED); 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; break;
} }
if (level == NXT_LOG_ERR && action->u.fallback != NULL) { if (level == NXT_LOG_ERR && action->u.share.fallback != NULL) {
return action->u.fallback; return action->u.share.fallback;
} }
if (status != NXT_HTTP_NOT_FOUND) { 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); nxt_file_close(task, f);
if (nxt_slow_path(!nxt_is_dir(&fi))) { if (nxt_slow_path(!nxt_is_dir(&fi))) {
if (action->u.fallback != NULL) { if (action->u.share.fallback != NULL) {
return action->u.fallback; return action->u.share.fallback;
} }
nxt_log(task, NXT_LOG_ERR, "\"%FN\" is not a regular file", 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; return NXT_DECLINED;
} }
action->u.application = app; action->u.app.application = app;
action->handler = nxt_http_application_handler; action->handler = nxt_http_application_handler;
return NXT_OK; return NXT_OK;