Replacing pass with action.
This commit is contained in:
@@ -161,10 +161,10 @@ struct nxt_http_request_s {
|
|||||||
typedef struct nxt_http_route_s nxt_http_route_t;
|
typedef struct nxt_http_route_s nxt_http_route_t;
|
||||||
|
|
||||||
|
|
||||||
struct nxt_http_pass_s {
|
struct nxt_http_action_s {
|
||||||
nxt_http_pass_t *(*handler)(nxt_task_t *task,
|
nxt_http_action_t *(*handler)(nxt_task_t *task,
|
||||||
nxt_http_request_t *r,
|
nxt_http_request_t *r,
|
||||||
nxt_http_pass_t *pass);
|
nxt_http_action_t *action);
|
||||||
union {
|
union {
|
||||||
nxt_http_route_t *route;
|
nxt_http_route_t *route;
|
||||||
nxt_app_t *application;
|
nxt_app_t *application;
|
||||||
@@ -238,24 +238,24 @@ nxt_int_t nxt_http_request_content_length(void *ctx, nxt_http_field_t *field,
|
|||||||
|
|
||||||
nxt_http_routes_t *nxt_http_routes_create(nxt_task_t *task,
|
nxt_http_routes_t *nxt_http_routes_create(nxt_task_t *task,
|
||||||
nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *routes_conf);
|
nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *routes_conf);
|
||||||
nxt_http_pass_t *nxt_http_pass_create(nxt_task_t *task,
|
nxt_http_action_t *nxt_http_action_create(nxt_task_t *task,
|
||||||
nxt_router_temp_conf_t *tmcf, nxt_str_t *name);
|
nxt_router_temp_conf_t *tmcf, nxt_str_t *name);
|
||||||
void nxt_http_routes_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf);
|
void nxt_http_routes_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf);
|
||||||
nxt_http_pass_t *nxt_http_pass_application(nxt_task_t *task,
|
nxt_http_action_t *nxt_http_pass_application(nxt_task_t *task,
|
||||||
nxt_router_temp_conf_t *tmcf, nxt_str_t *name);
|
nxt_router_temp_conf_t *tmcf, nxt_str_t *name);
|
||||||
void nxt_http_routes_cleanup(nxt_task_t *task, nxt_http_routes_t *routes);
|
void nxt_http_routes_cleanup(nxt_task_t *task, nxt_http_routes_t *routes);
|
||||||
void nxt_http_pass_cleanup(nxt_task_t *task, nxt_http_pass_t *pass);
|
void nxt_http_action_cleanup(nxt_task_t *task, nxt_http_action_t *action);
|
||||||
|
|
||||||
nxt_http_pass_t *nxt_http_static_handler(nxt_task_t *task,
|
nxt_http_action_t *nxt_http_static_handler(nxt_task_t *task,
|
||||||
nxt_http_request_t *r, nxt_http_pass_t *pass);
|
nxt_http_request_t *r, nxt_http_action_t *action);
|
||||||
nxt_int_t nxt_http_static_mtypes_init(nxt_mp_t *mp, nxt_lvlhsh_t *hash);
|
nxt_int_t nxt_http_static_mtypes_init(nxt_mp_t *mp, nxt_lvlhsh_t *hash);
|
||||||
nxt_int_t nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash,
|
nxt_int_t nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash,
|
||||||
nxt_str_t *extension, nxt_str_t *type);
|
nxt_str_t *extension, nxt_str_t *type);
|
||||||
nxt_str_t *nxt_http_static_mtypes_hash_find(nxt_lvlhsh_t *hash,
|
nxt_str_t *nxt_http_static_mtypes_hash_find(nxt_lvlhsh_t *hash,
|
||||||
nxt_str_t *extension);
|
nxt_str_t *extension);
|
||||||
|
|
||||||
nxt_http_pass_t *nxt_http_request_application(nxt_task_t *task,
|
nxt_http_action_t *nxt_http_application_handler(nxt_task_t *task,
|
||||||
nxt_http_request_t *r, nxt_http_pass_t *pass);
|
nxt_http_request_t *r, nxt_http_action_t *action);
|
||||||
|
|
||||||
extern nxt_time_string_t nxt_http_date_cache;
|
extern nxt_time_string_t nxt_http_date_cache;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
static nxt_int_t nxt_http_validate_host(nxt_str_t *host, nxt_mp_t *mp);
|
static nxt_int_t nxt_http_validate_host(nxt_str_t *host, nxt_mp_t *mp);
|
||||||
static void nxt_http_request_start(nxt_task_t *task, void *obj, void *data);
|
static void nxt_http_request_start(nxt_task_t *task, void *obj, void *data);
|
||||||
static void nxt_http_request_pass(nxt_task_t *task, void *obj, void *data);
|
static void nxt_http_request_action(nxt_task_t *task, void *obj, void *data);
|
||||||
static void nxt_http_request_proto_info(nxt_task_t *task,
|
static void nxt_http_request_proto_info(nxt_task_t *task,
|
||||||
nxt_http_request_t *r);
|
nxt_http_request_t *r);
|
||||||
static void nxt_http_request_mem_buf_completion(nxt_task_t *task, void *obj,
|
static void nxt_http_request_mem_buf_completion(nxt_task_t *task, void *obj,
|
||||||
@@ -278,33 +278,33 @@ nxt_http_request_start(nxt_task_t *task, void *obj, void *data)
|
|||||||
static const nxt_http_request_state_t nxt_http_request_body_state
|
static const nxt_http_request_state_t nxt_http_request_body_state
|
||||||
nxt_aligned(64) =
|
nxt_aligned(64) =
|
||||||
{
|
{
|
||||||
.ready_handler = nxt_http_request_pass,
|
.ready_handler = nxt_http_request_action,
|
||||||
.error_handler = nxt_http_request_close_handler,
|
.error_handler = nxt_http_request_close_handler,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nxt_http_request_pass(nxt_task_t *task, void *obj, void *data)
|
nxt_http_request_action(nxt_task_t *task, void *obj, void *data)
|
||||||
{
|
{
|
||||||
nxt_http_pass_t *pass;
|
nxt_http_action_t *action;
|
||||||
nxt_http_request_t *r;
|
nxt_http_request_t *r;
|
||||||
|
|
||||||
r = obj;
|
r = obj;
|
||||||
|
|
||||||
pass = r->conf->socket_conf->pass;
|
action = r->conf->socket_conf->action;
|
||||||
|
|
||||||
if (nxt_fast_path(pass != NULL)) {
|
if (nxt_fast_path(action != NULL)) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
nxt_debug(task, "http request route: %V", &pass->name);
|
nxt_debug(task, "http request route: %V", &action->name);
|
||||||
|
|
||||||
pass = pass->handler(task, r, pass);
|
action = action->handler(task, r, action);
|
||||||
|
|
||||||
if (pass == NULL) {
|
if (action == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pass == NXT_HTTP_PASS_ERROR) {
|
if (action == NXT_HTTP_ACTION_ERROR) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,13 +315,13 @@ nxt_http_request_pass(nxt_task_t *task, void *obj, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nxt_http_pass_t *
|
nxt_http_action_t *
|
||||||
nxt_http_request_application(nxt_task_t *task, nxt_http_request_t *r,
|
nxt_http_application_handler(nxt_task_t *task, nxt_http_request_t *r,
|
||||||
nxt_http_pass_t *pass)
|
nxt_http_action_t *action)
|
||||||
{
|
{
|
||||||
nxt_event_engine_t *engine;
|
nxt_event_engine_t *engine;
|
||||||
|
|
||||||
nxt_debug(task, "http request application");
|
nxt_debug(task, "http application handler");
|
||||||
|
|
||||||
nxt_mp_retain(r->mem_pool);
|
nxt_mp_retain(r->mem_pool);
|
||||||
|
|
||||||
@@ -344,7 +344,7 @@ nxt_http_request_application(nxt_task_t *task, nxt_http_request_t *r,
|
|||||||
nxt_str_set(&r->server_name, "localhost");
|
nxt_str_set(&r->server_name, "localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt_router_process_http_request(task, r, pass->u.application);
|
nxt_router_process_http_request(task, r, action->u.application);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ typedef enum {
|
|||||||
} nxt_http_route_pattern_case_t;
|
} nxt_http_route_pattern_case_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
nxt_conf_value_t *pass;
|
||||||
|
nxt_conf_value_t *share;
|
||||||
|
} nxt_http_route_action_conf_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
nxt_conf_value_t *host;
|
nxt_conf_value_t *host;
|
||||||
nxt_conf_value_t *uri;
|
nxt_conf_value_t *uri;
|
||||||
@@ -119,7 +125,7 @@ typedef union {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t items;
|
uint32_t items;
|
||||||
nxt_http_pass_t pass;
|
nxt_http_action_t action;
|
||||||
nxt_http_route_test_t test[0];
|
nxt_http_route_test_t test[0];
|
||||||
} nxt_http_route_match_t;
|
} nxt_http_route_match_t;
|
||||||
|
|
||||||
@@ -152,6 +158,8 @@ static nxt_http_route_t *nxt_http_route_create(nxt_task_t *task,
|
|||||||
nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv);
|
nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv);
|
||||||
static nxt_http_route_match_t *nxt_http_route_match_create(nxt_task_t *task,
|
static nxt_http_route_match_t *nxt_http_route_match_create(nxt_task_t *task,
|
||||||
nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv);
|
nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv);
|
||||||
|
static nxt_int_t nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf,
|
||||||
|
nxt_conf_value_t *cv, nxt_http_route_match_t *match);
|
||||||
static nxt_http_route_table_t *nxt_http_route_table_create(nxt_task_t *task,
|
static nxt_http_route_table_t *nxt_http_route_table_create(nxt_task_t *task,
|
||||||
nxt_mp_t *mp, nxt_conf_value_t *table_cv, nxt_http_route_object_t object,
|
nxt_mp_t *mp, nxt_conf_value_t *table_cv, nxt_http_route_object_t object,
|
||||||
nxt_bool_t case_sensitive);
|
nxt_bool_t case_sensitive);
|
||||||
@@ -173,15 +181,15 @@ static u_char *nxt_http_route_pattern_copy(nxt_mp_t *mp, nxt_str_t *test,
|
|||||||
|
|
||||||
static void nxt_http_route_resolve(nxt_task_t *task,
|
static void nxt_http_route_resolve(nxt_task_t *task,
|
||||||
nxt_router_temp_conf_t *tmcf, nxt_http_route_t *route);
|
nxt_router_temp_conf_t *tmcf, nxt_http_route_t *route);
|
||||||
static void nxt_http_pass_resolve(nxt_task_t *task,
|
static void nxt_http_action_resolve(nxt_task_t *task,
|
||||||
nxt_router_temp_conf_t *tmcf, nxt_http_pass_t *pass);
|
nxt_router_temp_conf_t *tmcf, nxt_http_action_t *action);
|
||||||
static nxt_http_route_t *nxt_http_route_find(nxt_http_routes_t *routes,
|
static nxt_http_route_t *nxt_http_route_find(nxt_http_routes_t *routes,
|
||||||
nxt_str_t *name);
|
nxt_str_t *name);
|
||||||
static void nxt_http_route_cleanup(nxt_task_t *task, nxt_http_route_t *routes);
|
static void nxt_http_route_cleanup(nxt_task_t *task, nxt_http_route_t *routes);
|
||||||
|
|
||||||
static nxt_http_pass_t *nxt_http_route_pass(nxt_task_t *task,
|
static nxt_http_action_t *nxt_http_route_handler(nxt_task_t *task,
|
||||||
nxt_http_request_t *r, nxt_http_pass_t *start);
|
nxt_http_request_t *r, nxt_http_action_t *start);
|
||||||
static nxt_http_pass_t *nxt_http_route_match(nxt_http_request_t *r,
|
static nxt_http_action_t *nxt_http_route_match(nxt_http_request_t *r,
|
||||||
nxt_http_route_match_t *match);
|
nxt_http_route_match_t *match);
|
||||||
static nxt_int_t nxt_http_route_table(nxt_http_request_t *r,
|
static nxt_int_t nxt_http_route_table(nxt_http_request_t *r,
|
||||||
nxt_http_route_table_t *table);
|
nxt_http_route_table_t *table);
|
||||||
@@ -367,16 +375,13 @@ nxt_http_route_match_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
uint32_t n;
|
uint32_t n;
|
||||||
nxt_mp_t *mp;
|
nxt_mp_t *mp;
|
||||||
nxt_int_t ret;
|
nxt_int_t ret;
|
||||||
nxt_str_t pass, *string;
|
nxt_conf_value_t *match_conf;
|
||||||
nxt_conf_value_t *match_conf, *pass_conf;
|
|
||||||
nxt_http_route_test_t *test;
|
nxt_http_route_test_t *test;
|
||||||
nxt_http_route_rule_t *rule;
|
nxt_http_route_rule_t *rule;
|
||||||
nxt_http_route_table_t *table;
|
nxt_http_route_table_t *table;
|
||||||
nxt_http_route_match_t *match;
|
nxt_http_route_match_t *match;
|
||||||
nxt_http_route_match_conf_t mtcf;
|
nxt_http_route_match_conf_t mtcf;
|
||||||
|
|
||||||
static nxt_str_t pass_path = nxt_string("/action/pass");
|
|
||||||
static nxt_str_t share_path = nxt_string("/action/share");
|
|
||||||
static nxt_str_t match_path = nxt_string("/match");
|
static nxt_str_t match_path = nxt_string("/match");
|
||||||
|
|
||||||
match_conf = nxt_conf_get_path(cv, &match_path);
|
match_conf = nxt_conf_get_path(cv, &match_path);
|
||||||
@@ -391,25 +396,12 @@ nxt_http_route_match_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
match->pass.u.route = NULL;
|
match->action.u.route = NULL;
|
||||||
match->pass.handler = NULL;
|
match->action.handler = NULL;
|
||||||
match->items = n;
|
match->items = n;
|
||||||
|
|
||||||
pass_conf = nxt_conf_get_path(cv, &pass_path);
|
ret = nxt_http_route_action_create(tmcf, cv, match);
|
||||||
|
if (nxt_slow_path(ret != NXT_OK)) {
|
||||||
if (pass_conf == NULL) {
|
|
||||||
pass_conf = nxt_conf_get_path(cv, &share_path);
|
|
||||||
if (nxt_slow_path(pass_conf == NULL)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
match->pass.handler = nxt_http_static_handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
nxt_conf_get_string(pass_conf, &pass);
|
|
||||||
|
|
||||||
string = nxt_str_dup(mp, &match->pass.name, &pass);
|
|
||||||
if (nxt_slow_path(string == NULL)) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,6 +508,64 @@ nxt_http_route_match_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static nxt_conf_map_t nxt_http_route_action_conf[] = {
|
||||||
|
{
|
||||||
|
nxt_string("pass"),
|
||||||
|
NXT_CONF_MAP_PTR,
|
||||||
|
offsetof(nxt_http_route_action_conf_t, pass)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nxt_string("share"),
|
||||||
|
NXT_CONF_MAP_PTR,
|
||||||
|
offsetof(nxt_http_route_action_conf_t, share)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static nxt_int_t
|
||||||
|
nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv,
|
||||||
|
nxt_http_route_match_t *match)
|
||||||
|
{
|
||||||
|
nxt_int_t ret;
|
||||||
|
nxt_str_t name, *string;
|
||||||
|
nxt_conf_value_t *conf, *action_conf;
|
||||||
|
nxt_http_route_action_conf_t accf;
|
||||||
|
|
||||||
|
static nxt_str_t action_path = nxt_string("/action");
|
||||||
|
|
||||||
|
action_conf = nxt_conf_get_path(cv, &action_path);
|
||||||
|
if (action_conf == NULL) {
|
||||||
|
return NXT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
nxt_memzero(&accf, sizeof(accf));
|
||||||
|
|
||||||
|
ret = nxt_conf_map_object(tmcf->mem_pool,
|
||||||
|
action_conf, nxt_http_route_action_conf,
|
||||||
|
nxt_nitems(nxt_http_route_action_conf), &accf);
|
||||||
|
if (ret != NXT_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf = accf.pass;
|
||||||
|
|
||||||
|
if (accf.share != NULL) {
|
||||||
|
conf = accf.share;
|
||||||
|
match->action.handler = nxt_http_static_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
nxt_conf_get_string(conf, &name);
|
||||||
|
|
||||||
|
string = nxt_str_dup(tmcf->router_conf->mem_pool,
|
||||||
|
&match->action.name, &name);
|
||||||
|
if (nxt_slow_path(string == NULL)) {
|
||||||
|
return NXT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NXT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static nxt_http_route_table_t *
|
static nxt_http_route_table_t *
|
||||||
nxt_http_route_table_create(nxt_task_t *task, nxt_mp_t *mp,
|
nxt_http_route_table_create(nxt_task_t *task, nxt_mp_t *mp,
|
||||||
nxt_conf_value_t *table_cv, nxt_http_route_object_t object,
|
nxt_conf_value_t *table_cv, nxt_http_route_object_t object,
|
||||||
@@ -877,17 +927,17 @@ static void
|
|||||||
nxt_http_route_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
nxt_http_route_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
||||||
nxt_http_route_t *route)
|
nxt_http_route_t *route)
|
||||||
{
|
{
|
||||||
nxt_http_pass_t *pass;
|
nxt_http_action_t *action;
|
||||||
nxt_http_route_match_t **match, **end;
|
nxt_http_route_match_t **match, **end;
|
||||||
|
|
||||||
match = &route->match[0];
|
match = &route->match[0];
|
||||||
end = match + route->items;
|
end = match + route->items;
|
||||||
|
|
||||||
while (match < end) {
|
while (match < end) {
|
||||||
pass = &(*match)->pass;
|
action = &(*match)->action;
|
||||||
|
|
||||||
if (pass->handler == NULL) {
|
if (action->handler == NULL) {
|
||||||
nxt_http_pass_resolve(task, tmcf, &(*match)->pass);
|
nxt_http_action_resolve(task, tmcf, &(*match)->action);
|
||||||
}
|
}
|
||||||
|
|
||||||
match++;
|
match++;
|
||||||
@@ -896,21 +946,21 @@ nxt_http_route_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nxt_http_pass_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
nxt_http_action_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
||||||
nxt_http_pass_t *pass)
|
nxt_http_action_t *action)
|
||||||
{
|
{
|
||||||
nxt_str_t name;
|
nxt_str_t name;
|
||||||
|
|
||||||
name = pass->name;
|
name = action->name;
|
||||||
|
|
||||||
if (nxt_str_start(&name, "applications/", 13)) {
|
if (nxt_str_start(&name, "applications/", 13)) {
|
||||||
name.length -= 13;
|
name.length -= 13;
|
||||||
name.start += 13;
|
name.start += 13;
|
||||||
|
|
||||||
pass->u.application = nxt_router_listener_application(tmcf, &name);
|
action->u.application = nxt_router_listener_application(tmcf, &name);
|
||||||
nxt_router_app_use(task, pass->u.application, 1);
|
nxt_router_app_use(task, action->u.application, 1);
|
||||||
|
|
||||||
pass->handler = nxt_http_request_application;
|
action->handler = nxt_http_application_handler;
|
||||||
|
|
||||||
} else if (nxt_str_start(&name, "routes", 6)) {
|
} else if (nxt_str_start(&name, "routes", 6)) {
|
||||||
|
|
||||||
@@ -923,9 +973,9 @@ nxt_http_pass_resolve(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
name.start += 7;
|
name.start += 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
pass->u.route = nxt_http_route_find(tmcf->router_conf->routes, &name);
|
action->u.route = nxt_http_route_find(tmcf->router_conf->routes, &name);
|
||||||
|
|
||||||
pass->handler = nxt_http_route_pass;
|
action->handler = nxt_http_route_handler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -950,46 +1000,48 @@ nxt_http_route_find(nxt_http_routes_t *routes, nxt_str_t *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nxt_http_pass_t *
|
nxt_http_action_t *
|
||||||
nxt_http_pass_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
nxt_http_action_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
||||||
nxt_str_t *name)
|
nxt_str_t *name)
|
||||||
{
|
{
|
||||||
nxt_http_pass_t *pass;
|
nxt_http_action_t *action;
|
||||||
|
|
||||||
pass = nxt_mp_alloc(tmcf->router_conf->mem_pool, sizeof(nxt_http_pass_t));
|
action = nxt_mp_alloc(tmcf->router_conf->mem_pool,
|
||||||
if (nxt_slow_path(pass == NULL)) {
|
sizeof(nxt_http_action_t));
|
||||||
|
if (nxt_slow_path(action == NULL)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pass->name = *name;
|
action->name = *name;
|
||||||
|
|
||||||
nxt_http_pass_resolve(task, tmcf, pass);
|
nxt_http_action_resolve(task, tmcf, action);
|
||||||
|
|
||||||
return pass;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* COMPATIBILITY: listener application. */
|
/* COMPATIBILITY: listener application. */
|
||||||
|
|
||||||
nxt_http_pass_t *
|
nxt_http_action_t *
|
||||||
nxt_http_pass_application(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
nxt_http_pass_application(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
||||||
nxt_str_t *name)
|
nxt_str_t *name)
|
||||||
{
|
{
|
||||||
nxt_http_pass_t *pass;
|
nxt_http_action_t *action;
|
||||||
|
|
||||||
pass = nxt_mp_alloc(tmcf->router_conf->mem_pool, sizeof(nxt_http_pass_t));
|
action = nxt_mp_alloc(tmcf->router_conf->mem_pool,
|
||||||
if (nxt_slow_path(pass == NULL)) {
|
sizeof(nxt_http_action_t));
|
||||||
|
if (nxt_slow_path(action == NULL)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pass->name = *name;
|
action->name = *name;
|
||||||
|
|
||||||
pass->u.application = nxt_router_listener_application(tmcf, name);
|
action->u.application = nxt_router_listener_application(tmcf, name);
|
||||||
nxt_router_app_use(task, pass->u.application, 1);
|
nxt_router_app_use(task, action->u.application, 1);
|
||||||
|
|
||||||
pass->handler = nxt_http_request_application;
|
action->handler = nxt_http_application_handler;
|
||||||
|
|
||||||
return pass;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1020,7 +1072,7 @@ nxt_http_route_cleanup(nxt_task_t *task, nxt_http_route_t *route)
|
|||||||
end = match + route->items;
|
end = match + route->items;
|
||||||
|
|
||||||
while (match < end) {
|
while (match < end) {
|
||||||
nxt_http_pass_cleanup(task, &(*match)->pass);
|
nxt_http_action_cleanup(task, &(*match)->action);
|
||||||
|
|
||||||
match++;
|
match++;
|
||||||
}
|
}
|
||||||
@@ -1028,20 +1080,20 @@ nxt_http_route_cleanup(nxt_task_t *task, nxt_http_route_t *route)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
nxt_http_pass_cleanup(nxt_task_t *task, nxt_http_pass_t *pass)
|
nxt_http_action_cleanup(nxt_task_t *task, nxt_http_action_t *action)
|
||||||
{
|
{
|
||||||
if (pass->handler == nxt_http_request_application) {
|
if (action->handler == nxt_http_application_handler) {
|
||||||
nxt_router_app_use(task, pass->u.application, -1);
|
nxt_router_app_use(task, action->u.application, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static nxt_http_pass_t *
|
static nxt_http_action_t *
|
||||||
nxt_http_route_pass(nxt_task_t *task, nxt_http_request_t *r,
|
nxt_http_route_handler(nxt_task_t *task, nxt_http_request_t *r,
|
||||||
nxt_http_pass_t *start)
|
nxt_http_action_t *start)
|
||||||
{
|
{
|
||||||
nxt_http_pass_t *pass;
|
|
||||||
nxt_http_route_t *route;
|
nxt_http_route_t *route;
|
||||||
|
nxt_http_action_t *action;
|
||||||
nxt_http_route_match_t **match, **end;
|
nxt_http_route_match_t **match, **end;
|
||||||
|
|
||||||
route = start->u.route;
|
route = start->u.route;
|
||||||
@@ -1049,9 +1101,9 @@ nxt_http_route_pass(nxt_task_t *task, nxt_http_request_t *r,
|
|||||||
end = match + route->items;
|
end = match + route->items;
|
||||||
|
|
||||||
while (match < end) {
|
while (match < end) {
|
||||||
pass = nxt_http_route_match(r, *match);
|
action = nxt_http_route_match(r, *match);
|
||||||
if (pass != NULL) {
|
if (action != NULL) {
|
||||||
return pass;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
match++;
|
match++;
|
||||||
@@ -1063,7 +1115,7 @@ nxt_http_route_pass(nxt_task_t *task, nxt_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static nxt_http_pass_t *
|
static nxt_http_action_t *
|
||||||
nxt_http_route_match(nxt_http_request_t *r, nxt_http_route_match_t *match)
|
nxt_http_route_match(nxt_http_request_t *r, nxt_http_route_match_t *match)
|
||||||
{
|
{
|
||||||
nxt_int_t ret;
|
nxt_int_t ret;
|
||||||
@@ -1081,14 +1133,14 @@ nxt_http_route_match(nxt_http_request_t *r, nxt_http_route_match_t *match)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
/* 0 => NULL, -1 => NXT_HTTP_PASS_ERROR. */
|
/* 0 => NULL, -1 => NXT_HTTP_ACTION_ERROR. */
|
||||||
return (nxt_http_pass_t *) (intptr_t) ret;
|
return (nxt_http_action_t *) (intptr_t) ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
test++;
|
test++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &match->pass;
|
return &match->action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ static void nxt_http_static_mtypes_hash_free(void *data, void *p);
|
|||||||
static const nxt_http_request_state_t nxt_http_static_send_state;
|
static const nxt_http_request_state_t nxt_http_static_send_state;
|
||||||
|
|
||||||
|
|
||||||
nxt_http_pass_t *
|
nxt_http_action_t *
|
||||||
nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r,
|
nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r,
|
||||||
nxt_http_pass_t *pass)
|
nxt_http_action_t *action)
|
||||||
{
|
{
|
||||||
size_t alloc, encode;
|
size_t alloc, encode;
|
||||||
u_char *p;
|
u_char *p;
|
||||||
@@ -76,7 +76,7 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r,
|
|||||||
nxt_str_null(&extension);
|
nxt_str_null(&extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
alloc = pass->name.length + r->path->length + index.length + 1;
|
alloc = action->name.length + r->path->length + index.length + 1;
|
||||||
|
|
||||||
f->name = nxt_mp_nget(r->mem_pool, alloc);
|
f->name = nxt_mp_nget(r->mem_pool, alloc);
|
||||||
if (nxt_slow_path(f->name == NULL)) {
|
if (nxt_slow_path(f->name == NULL)) {
|
||||||
@@ -84,7 +84,7 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
p = f->name;
|
p = f->name;
|
||||||
p = nxt_cpymem(p, pass->name.start, pass->name.length);
|
p = nxt_cpymem(p, action->name.start, action->name.length);
|
||||||
p = nxt_cpymem(p, r->path->start, r->path->length);
|
p = nxt_cpymem(p, r->path->start, r->path->length);
|
||||||
p = nxt_cpymem(p, index.start, index.length);
|
p = nxt_cpymem(p, index.start, index.length);
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|||||||
@@ -1172,8 +1172,8 @@ nxt_router_conf_error(nxt_task_t *task, nxt_router_temp_conf_t *tmcf)
|
|||||||
|
|
||||||
nxt_queue_each(skcf, &new_socket_confs, nxt_socket_conf_t, link) {
|
nxt_queue_each(skcf, &new_socket_confs, nxt_socket_conf_t, link) {
|
||||||
|
|
||||||
if (skcf->pass != NULL) {
|
if (skcf->action != NULL) {
|
||||||
nxt_http_pass_cleanup(task, skcf->pass);
|
nxt_http_action_cleanup(task, skcf->action);
|
||||||
}
|
}
|
||||||
|
|
||||||
} nxt_queue_loop;
|
} nxt_queue_loop;
|
||||||
@@ -1730,12 +1730,12 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
skcf->router_conf->count++;
|
skcf->router_conf->count++;
|
||||||
|
|
||||||
if (lscf.pass.length != 0) {
|
if (lscf.pass.length != 0) {
|
||||||
skcf->pass = nxt_http_pass_create(task, tmcf, &lscf.pass);
|
skcf->action = nxt_http_action_create(task, tmcf, &lscf.pass);
|
||||||
|
|
||||||
/* COMPATIBILITY: listener application. */
|
/* COMPATIBILITY: listener application. */
|
||||||
} else if (lscf.application.length > 0) {
|
} else if (lscf.application.length > 0) {
|
||||||
skcf->pass = nxt_http_pass_application(task, tmcf,
|
skcf->action = nxt_http_pass_application(task, tmcf,
|
||||||
&lscf.application);
|
&lscf.application);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3071,8 +3071,8 @@ nxt_router_conf_release(nxt_task_t *task, nxt_socket_conf_joint_t *joint)
|
|||||||
nxt_thread_spin_unlock(lock);
|
nxt_thread_spin_unlock(lock);
|
||||||
|
|
||||||
if (skcf != NULL) {
|
if (skcf != NULL) {
|
||||||
if (skcf->pass != NULL) {
|
if (skcf->action != NULL) {
|
||||||
nxt_http_pass_cleanup(task, skcf->pass);
|
nxt_http_action_cleanup(task, skcf->action);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (NXT_TLS)
|
#if (NXT_TLS)
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ typedef struct nxt_http_request_s nxt_http_request_t;
|
|||||||
#include <nxt_application.h>
|
#include <nxt_application.h>
|
||||||
|
|
||||||
|
|
||||||
typedef struct nxt_http_pass_s nxt_http_pass_t;
|
typedef struct nxt_http_action_s nxt_http_action_t;
|
||||||
typedef struct nxt_http_routes_s nxt_http_routes_t;
|
typedef struct nxt_http_routes_s nxt_http_routes_t;
|
||||||
typedef struct nxt_router_access_log_s nxt_router_access_log_t;
|
typedef struct nxt_router_access_log_s nxt_router_access_log_t;
|
||||||
|
|
||||||
|
|
||||||
#define NXT_HTTP_PASS_ERROR ((nxt_http_pass_t *) -1)
|
#define NXT_HTTP_ACTION_ERROR ((nxt_http_action_t *) -1)
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -154,7 +154,7 @@ typedef struct {
|
|||||||
nxt_queue_link_t link;
|
nxt_queue_link_t link;
|
||||||
nxt_router_conf_t *router_conf;
|
nxt_router_conf_t *router_conf;
|
||||||
|
|
||||||
nxt_http_pass_t *pass;
|
nxt_http_action_t *action;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A listen socket time can be shorter than socket configuration life
|
* A listen socket time can be shorter than socket configuration life
|
||||||
|
|||||||
Reference in New Issue
Block a user