Router: split nxt_http_return_conf_t from nxt_http_action_t.
No functional changes.
This commit is contained in:
@@ -201,15 +201,29 @@ typedef struct nxt_http_route_s nxt_http_route_t;
|
|||||||
typedef struct nxt_http_route_rule_s nxt_http_route_rule_t;
|
typedef struct nxt_http_route_rule_s nxt_http_route_rule_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
nxt_conf_value_t *pass;
|
||||||
|
nxt_conf_value_t *ret;
|
||||||
|
nxt_str_t location;
|
||||||
|
nxt_conf_value_t *proxy;
|
||||||
|
nxt_conf_value_t *share;
|
||||||
|
nxt_str_t chroot;
|
||||||
|
nxt_conf_value_t *follow_symlinks;
|
||||||
|
nxt_conf_value_t *traverse_mounts;
|
||||||
|
nxt_conf_value_t *types;
|
||||||
|
nxt_conf_value_t *fallback;
|
||||||
|
} nxt_http_action_conf_t;
|
||||||
|
|
||||||
|
|
||||||
struct nxt_http_action_s {
|
struct nxt_http_action_s {
|
||||||
nxt_http_action_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_action_t *action);
|
nxt_http_action_t *action);
|
||||||
union {
|
union {
|
||||||
|
void *conf;
|
||||||
nxt_http_route_t *route;
|
nxt_http_route_t *route;
|
||||||
nxt_upstream_t *upstream;
|
nxt_upstream_t *upstream;
|
||||||
uint32_t upstream_number;
|
uint32_t upstream_number;
|
||||||
nxt_http_status_t return_code;
|
|
||||||
nxt_var_t *var;
|
nxt_var_t *var;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@@ -319,8 +333,8 @@ nxt_int_t nxt_upstreams_joint_create(nxt_router_temp_conf_t *tmcf,
|
|||||||
void nxt_http_request_action(nxt_task_t *task, nxt_http_request_t *r,
|
void nxt_http_request_action(nxt_task_t *task, nxt_http_request_t *r,
|
||||||
nxt_http_action_t *action);
|
nxt_http_action_t *action);
|
||||||
|
|
||||||
nxt_http_action_t *nxt_http_return_handler(nxt_task_t *task,
|
nxt_int_t nxt_http_return_init(nxt_mp_t *mp, nxt_http_action_t *action,
|
||||||
nxt_http_request_t *r, nxt_http_action_t *action);
|
nxt_http_action_conf_t *acf);
|
||||||
|
|
||||||
nxt_http_action_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_action_t *action);
|
nxt_http_request_t *r, nxt_http_action_t *action);
|
||||||
|
|||||||
@@ -7,29 +7,90 @@
|
|||||||
#include <nxt_http.h>
|
#include <nxt_http.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
nxt_http_status_t status;
|
||||||
|
nxt_str_t location;
|
||||||
|
} nxt_http_return_conf_t;
|
||||||
|
|
||||||
|
|
||||||
|
static nxt_http_action_t *nxt_http_return(nxt_task_t *task,
|
||||||
|
nxt_http_request_t *r, nxt_http_action_t *action);
|
||||||
|
|
||||||
|
|
||||||
static const nxt_http_request_state_t nxt_http_return_send_state;
|
static const nxt_http_request_state_t nxt_http_return_send_state;
|
||||||
|
|
||||||
|
|
||||||
|
nxt_int_t
|
||||||
|
nxt_http_return_init(nxt_mp_t *mp, nxt_http_action_t *action,
|
||||||
|
nxt_http_action_conf_t *acf)
|
||||||
|
{
|
||||||
|
nxt_str_t *loc;
|
||||||
|
nxt_uint_t encode;
|
||||||
|
nxt_http_return_conf_t *conf;
|
||||||
|
|
||||||
|
conf = nxt_mp_zget(mp, sizeof(nxt_http_return_conf_t));
|
||||||
|
if (nxt_slow_path(conf == NULL)) {
|
||||||
|
return NXT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
action->handler = nxt_http_return;
|
||||||
|
action->u.conf = conf;
|
||||||
|
|
||||||
|
conf->status = nxt_conf_get_number(acf->ret);
|
||||||
|
|
||||||
|
if (acf->location.length > 0) {
|
||||||
|
if (nxt_is_complex_uri_encoded(acf->location.start,
|
||||||
|
acf->location.length))
|
||||||
|
{
|
||||||
|
loc = nxt_str_dup(mp, &conf->location, &acf->location);
|
||||||
|
if (nxt_slow_path(loc == NULL)) {
|
||||||
|
return NXT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
loc = &conf->location;
|
||||||
|
|
||||||
|
encode = nxt_encode_complex_uri(NULL, acf->location.start,
|
||||||
|
acf->location.length);
|
||||||
|
loc->length = acf->location.length + encode * 2;
|
||||||
|
|
||||||
|
loc->start = nxt_mp_nget(mp, loc->length);
|
||||||
|
if (nxt_slow_path(loc->start == NULL)) {
|
||||||
|
return NXT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
nxt_encode_complex_uri(loc->start, acf->location.start,
|
||||||
|
acf->location.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NXT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
nxt_http_action_t *
|
nxt_http_action_t *
|
||||||
nxt_http_return_handler(nxt_task_t *task, nxt_http_request_t *r,
|
nxt_http_return(nxt_task_t *task, nxt_http_request_t *r,
|
||||||
nxt_http_action_t *action)
|
nxt_http_action_t *action)
|
||||||
{
|
{
|
||||||
nxt_http_field_t *field;
|
nxt_http_field_t *field;
|
||||||
nxt_http_status_t status;
|
nxt_http_return_conf_t *conf;
|
||||||
|
|
||||||
status = action->u.return_code;
|
conf = action->u.conf;
|
||||||
|
|
||||||
if (status >= NXT_HTTP_BAD_REQUEST
|
nxt_debug(task, "http return: %d (loc: \"%V\")",
|
||||||
&& status <= NXT_HTTP_SERVER_ERROR_MAX)
|
conf->status, &conf->location);
|
||||||
|
|
||||||
|
if (conf->status >= NXT_HTTP_BAD_REQUEST
|
||||||
|
&& conf->status <= NXT_HTTP_SERVER_ERROR_MAX)
|
||||||
{
|
{
|
||||||
nxt_http_request_error(task, r, status);
|
nxt_http_request_error(task, r, conf->status);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->status = status;
|
r->status = conf->status;
|
||||||
r->resp.content_length_n = 0;
|
r->resp.content_length_n = 0;
|
||||||
|
|
||||||
if (action->name.length > 0) {
|
if (conf->location.length > 0) {
|
||||||
field = nxt_list_zero_add(r->resp.fields);
|
field = nxt_list_zero_add(r->resp.fields);
|
||||||
if (nxt_slow_path(field == NULL)) {
|
if (nxt_slow_path(field == NULL)) {
|
||||||
nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR);
|
nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
@@ -38,8 +99,8 @@ nxt_http_return_handler(nxt_task_t *task, nxt_http_request_t *r,
|
|||||||
|
|
||||||
nxt_http_field_name_set(field, "Location");
|
nxt_http_field_name_set(field, "Location");
|
||||||
|
|
||||||
field->value = action->name.start;
|
field->value = conf->location.start;
|
||||||
field->value_length = action->name.length;
|
field->value_length = conf->location.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->state = &nxt_http_return_send_state;
|
r->state = &nxt_http_return_send_state;
|
||||||
|
|||||||
@@ -46,20 +46,6 @@ typedef enum {
|
|||||||
} nxt_http_route_encoding_t;
|
} nxt_http_route_encoding_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
nxt_conf_value_t *pass;
|
|
||||||
nxt_conf_value_t *ret;
|
|
||||||
nxt_str_t location;
|
|
||||||
nxt_conf_value_t *proxy;
|
|
||||||
nxt_conf_value_t *share;
|
|
||||||
nxt_str_t chroot;
|
|
||||||
nxt_conf_value_t *follow_symlinks;
|
|
||||||
nxt_conf_value_t *traverse_mounts;
|
|
||||||
nxt_conf_value_t *types;
|
|
||||||
nxt_conf_value_t *fallback;
|
|
||||||
} 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;
|
||||||
@@ -199,7 +185,7 @@ 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_task_t *task,
|
static nxt_int_t nxt_http_action_init(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,
|
||||||
nxt_http_action_t *action);
|
nxt_http_action_t *action);
|
||||||
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,
|
||||||
@@ -476,7 +462,7 @@ nxt_http_route_match_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = nxt_http_route_action_create(task, tmcf, action_conf, &match->action);
|
ret = nxt_http_action_init(task, tmcf, action_conf, &match->action);
|
||||||
if (nxt_slow_path(ret != NXT_OK)) {
|
if (nxt_slow_path(ret != NXT_OK)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -617,77 +603,76 @@ static nxt_conf_map_t nxt_http_route_action_conf[] = {
|
|||||||
{
|
{
|
||||||
nxt_string("pass"),
|
nxt_string("pass"),
|
||||||
NXT_CONF_MAP_PTR,
|
NXT_CONF_MAP_PTR,
|
||||||
offsetof(nxt_http_route_action_conf_t, pass)
|
offsetof(nxt_http_action_conf_t, pass)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
nxt_string("return"),
|
nxt_string("return"),
|
||||||
NXT_CONF_MAP_PTR,
|
NXT_CONF_MAP_PTR,
|
||||||
offsetof(nxt_http_route_action_conf_t, ret)
|
offsetof(nxt_http_action_conf_t, ret)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
nxt_string("location"),
|
nxt_string("location"),
|
||||||
NXT_CONF_MAP_STR,
|
NXT_CONF_MAP_STR,
|
||||||
offsetof(nxt_http_route_action_conf_t, location)
|
offsetof(nxt_http_action_conf_t, location)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
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_action_conf_t, proxy)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
nxt_string("share"),
|
nxt_string("share"),
|
||||||
NXT_CONF_MAP_PTR,
|
NXT_CONF_MAP_PTR,
|
||||||
offsetof(nxt_http_route_action_conf_t, share)
|
offsetof(nxt_http_action_conf_t, share)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
nxt_string("chroot"),
|
nxt_string("chroot"),
|
||||||
NXT_CONF_MAP_STR,
|
NXT_CONF_MAP_STR,
|
||||||
offsetof(nxt_http_route_action_conf_t, chroot)
|
offsetof(nxt_http_action_conf_t, chroot)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
nxt_string("follow_symlinks"),
|
nxt_string("follow_symlinks"),
|
||||||
NXT_CONF_MAP_PTR,
|
NXT_CONF_MAP_PTR,
|
||||||
offsetof(nxt_http_route_action_conf_t, follow_symlinks)
|
offsetof(nxt_http_action_conf_t, follow_symlinks)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
nxt_string("traverse_mounts"),
|
nxt_string("traverse_mounts"),
|
||||||
NXT_CONF_MAP_PTR,
|
NXT_CONF_MAP_PTR,
|
||||||
offsetof(nxt_http_route_action_conf_t, traverse_mounts)
|
offsetof(nxt_http_action_conf_t, traverse_mounts)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
nxt_string("types"),
|
nxt_string("types"),
|
||||||
NXT_CONF_MAP_PTR,
|
NXT_CONF_MAP_PTR,
|
||||||
offsetof(nxt_http_route_action_conf_t, types)
|
offsetof(nxt_http_action_conf_t, types)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
nxt_string("fallback"),
|
nxt_string("fallback"),
|
||||||
NXT_CONF_MAP_PTR,
|
NXT_CONF_MAP_PTR,
|
||||||
offsetof(nxt_http_route_action_conf_t, fallback)
|
offsetof(nxt_http_action_conf_t, fallback)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static nxt_int_t
|
static nxt_int_t
|
||||||
nxt_http_route_action_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
nxt_http_action_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
||||||
nxt_conf_value_t *cv, nxt_http_action_t *action)
|
nxt_conf_value_t *cv, nxt_http_action_t *action)
|
||||||
{
|
{
|
||||||
#if (NXT_HAVE_OPENAT2)
|
#if (NXT_HAVE_OPENAT2)
|
||||||
u_char *p;
|
u_char *p;
|
||||||
uint8_t slash;
|
uint8_t slash;
|
||||||
nxt_str_t *chroot;
|
nxt_str_t *chroot;
|
||||||
#endif
|
#endif
|
||||||
nxt_mp_t *mp;
|
nxt_mp_t *mp;
|
||||||
nxt_int_t ret;
|
nxt_int_t ret;
|
||||||
nxt_str_t name, *string;
|
nxt_str_t name, *string;
|
||||||
nxt_uint_t encode;
|
nxt_conf_value_t *conf;
|
||||||
nxt_conf_value_t *conf;
|
nxt_http_route_rule_t *rule;
|
||||||
nxt_http_route_rule_t *rule;
|
nxt_http_action_conf_t acf;
|
||||||
nxt_http_route_action_conf_t accf;
|
|
||||||
|
|
||||||
nxt_memzero(&accf, sizeof(accf));
|
nxt_memzero(&acf, sizeof(acf));
|
||||||
|
|
||||||
ret = nxt_conf_map_object(tmcf->mem_pool, cv, nxt_http_route_action_conf,
|
ret = nxt_conf_map_object(tmcf->mem_pool, cv, nxt_http_route_action_conf,
|
||||||
nxt_nitems(nxt_http_route_action_conf), &accf);
|
nxt_nitems(nxt_http_route_action_conf), &acf);
|
||||||
if (ret != NXT_OK) {
|
if (ret != NXT_OK) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -696,47 +681,18 @@ nxt_http_route_action_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
|
|
||||||
mp = tmcf->router_conf->mem_pool;
|
mp = tmcf->router_conf->mem_pool;
|
||||||
|
|
||||||
if (accf.ret != NULL) {
|
if (acf.ret != NULL) {
|
||||||
action->handler = nxt_http_return_handler;
|
return nxt_http_return_init(mp, action, &acf);
|
||||||
action->u.return_code = nxt_conf_get_number(accf.ret);
|
|
||||||
|
|
||||||
if (accf.location.length > 0) {
|
|
||||||
if (nxt_is_complex_uri_encoded(accf.location.start,
|
|
||||||
accf.location.length))
|
|
||||||
{
|
|
||||||
string = nxt_str_dup(mp, &action->name, &accf.location);
|
|
||||||
if (nxt_slow_path(string == NULL)) {
|
|
||||||
return NXT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
string = &action->name;
|
|
||||||
|
|
||||||
encode = nxt_encode_complex_uri(NULL, accf.location.start,
|
|
||||||
accf.location.length);
|
|
||||||
string->length = accf.location.length + encode * 2;
|
|
||||||
|
|
||||||
string->start = nxt_mp_nget(mp, string->length);
|
|
||||||
if (nxt_slow_path(string->start == NULL)) {
|
|
||||||
return NXT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
nxt_encode_complex_uri(string->start, accf.location.start,
|
|
||||||
accf.location.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NXT_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accf.share != NULL) {
|
if (acf.share != NULL) {
|
||||||
conf = accf.share;
|
conf = acf.share;
|
||||||
|
|
||||||
} else if (accf.proxy != NULL) {
|
} else if (acf.proxy != NULL) {
|
||||||
conf = accf.proxy;
|
conf = acf.proxy;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
conf = accf.pass;
|
conf = acf.pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt_conf_get_string(conf, &name);
|
nxt_conf_get_string(conf, &name);
|
||||||
@@ -746,11 +702,11 @@ nxt_http_route_action_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
return NXT_ERROR;
|
return NXT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accf.share != NULL) {
|
if (acf.share != NULL) {
|
||||||
action->handler = nxt_http_static_handler;
|
action->handler = nxt_http_static_handler;
|
||||||
|
|
||||||
#if (NXT_HAVE_OPENAT2)
|
#if (NXT_HAVE_OPENAT2)
|
||||||
string = &accf.chroot;
|
string = &acf.chroot;
|
||||||
chroot = &action->u.share.chroot;
|
chroot = &action->u.share.chroot;
|
||||||
|
|
||||||
if (string->length > 0) {
|
if (string->length > 0) {
|
||||||
@@ -774,21 +730,21 @@ nxt_http_route_action_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accf.follow_symlinks != NULL
|
if (acf.follow_symlinks != NULL
|
||||||
&& !nxt_conf_get_boolean(accf.follow_symlinks))
|
&& !nxt_conf_get_boolean(acf.follow_symlinks))
|
||||||
{
|
{
|
||||||
action->u.share.resolve |= RESOLVE_NO_SYMLINKS;
|
action->u.share.resolve |= RESOLVE_NO_SYMLINKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accf.traverse_mounts != NULL
|
if (acf.traverse_mounts != NULL
|
||||||
&& !nxt_conf_get_boolean(accf.traverse_mounts))
|
&& !nxt_conf_get_boolean(acf.traverse_mounts))
|
||||||
{
|
{
|
||||||
action->u.share.resolve |= RESOLVE_NO_XDEV;
|
action->u.share.resolve |= RESOLVE_NO_XDEV;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (accf.types != NULL) {
|
if (acf.types != NULL) {
|
||||||
rule = nxt_http_route_rule_create(task, mp, accf.types, 0,
|
rule = nxt_http_route_rule_create(task, mp, acf.types, 0,
|
||||||
NXT_HTTP_ROUTE_PATTERN_LOWCASE,
|
NXT_HTTP_ROUTE_PATTERN_LOWCASE,
|
||||||
NXT_HTTP_ROUTE_ENCODING_NONE);
|
NXT_HTTP_ROUTE_ENCODING_NONE);
|
||||||
if (nxt_slow_path(rule == NULL)) {
|
if (nxt_slow_path(rule == NULL)) {
|
||||||
@@ -798,21 +754,21 @@ nxt_http_route_action_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
|
|||||||
action->u.share.types = rule;
|
action->u.share.types = rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accf.fallback != NULL) {
|
if (acf.fallback != NULL) {
|
||||||
action->u.share.fallback = nxt_mp_alloc(mp,
|
action->u.share.fallback = nxt_mp_alloc(mp,
|
||||||
sizeof(nxt_http_action_t));
|
sizeof(nxt_http_action_t));
|
||||||
if (nxt_slow_path(action->u.share.fallback == NULL)) {
|
if (nxt_slow_path(action->u.share.fallback == NULL)) {
|
||||||
return NXT_ERROR;
|
return NXT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nxt_http_route_action_create(task, tmcf, accf.fallback,
|
return nxt_http_action_init(task, tmcf, acf.fallback,
|
||||||
action->u.share.fallback);
|
action->u.share.fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NXT_OK;
|
return NXT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accf.proxy != NULL) {
|
if (acf.proxy != NULL) {
|
||||||
return nxt_http_proxy_create(mp, action);
|
return nxt_http_proxy_create(mp, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user