mirror of
https://github.com/nginx/nginx.git
synced 2025-02-25 18:55:26 -06:00
return code text
This commit is contained in:
parent
01213e18a7
commit
4c1b0770ca
@ -52,7 +52,7 @@ static ngx_command_t ngx_http_rewrite_commands[] = {
|
|||||||
|
|
||||||
{ ngx_string("return"),
|
{ ngx_string("return"),
|
||||||
NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
||||||
|NGX_CONF_TAKE1,
|
|NGX_CONF_TAKE12,
|
||||||
ngx_http_rewrite_return,
|
ngx_http_rewrite_return,
|
||||||
NGX_HTTP_LOC_CONF_OFFSET,
|
NGX_HTTP_LOC_CONF_OFFSET,
|
||||||
0,
|
0,
|
||||||
@ -433,8 +433,10 @@ ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
{
|
{
|
||||||
ngx_http_rewrite_loc_conf_t *lcf = conf;
|
ngx_http_rewrite_loc_conf_t *lcf = conf;
|
||||||
|
|
||||||
ngx_str_t *value;
|
u_char *p;
|
||||||
ngx_http_script_return_code_t *ret;
|
ngx_str_t *value, *v;
|
||||||
|
ngx_http_script_return_code_t *ret;
|
||||||
|
ngx_http_compile_complex_value_t ccv;
|
||||||
|
|
||||||
ret = ngx_http_script_start_code(cf->pool, &lcf->codes,
|
ret = ngx_http_script_start_code(cf->pool, &lcf->codes,
|
||||||
sizeof(ngx_http_script_return_code_t));
|
sizeof(ngx_http_script_return_code_t));
|
||||||
@ -444,12 +446,46 @@ ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
ret->code = ngx_http_script_return_code;
|
ngx_memzero(ret, sizeof(ngx_http_script_return_code_t));
|
||||||
ret->null = (uintptr_t) NULL;
|
|
||||||
|
|
||||||
ret->status = ngx_atoi(value[1].data, value[1].len);
|
ret->code = ngx_http_script_return_code;
|
||||||
|
|
||||||
|
p = value[1].data;
|
||||||
|
|
||||||
|
ret->status = ngx_atoi(p, value[1].len);
|
||||||
|
|
||||||
if (ret->status == (uintptr_t) NGX_ERROR) {
|
if (ret->status == (uintptr_t) NGX_ERROR) {
|
||||||
|
|
||||||
|
if (cf->args->nelts == 2
|
||||||
|
&& (ngx_strncmp(p, "http://", sizeof("http://") - 1) == 0
|
||||||
|
|| ngx_strncmp(p, "https://", sizeof("https://") - 1) == 0
|
||||||
|
|| ngx_strncmp(p, "$scheme", sizeof("$scheme") - 1) == 0))
|
||||||
|
{
|
||||||
|
ret->status = NGX_HTTP_MOVED_TEMPORARILY;
|
||||||
|
v = &value[1];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
|
"invalid return code \"%V\"", &value[1]);
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (cf->args->nelts == 2) {
|
||||||
|
return NGX_CONF_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = &value[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
|
||||||
|
|
||||||
|
ccv.cf = cf;
|
||||||
|
ccv.value = v;
|
||||||
|
ccv.complex_value = &ret->text;
|
||||||
|
|
||||||
|
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,7 +509,7 @@ ngx_http_init_phase_handlers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf)
|
|||||||
if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) {
|
if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) {
|
||||||
cmcf->phase_engine.server_rewrite_index = n;
|
cmcf->phase_engine.server_rewrite_index = n;
|
||||||
}
|
}
|
||||||
checker = ngx_http_core_generic_phase;
|
checker = ngx_http_core_rewrite_phase;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -526,7 +526,7 @@ ngx_http_init_phase_handlers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf)
|
|||||||
if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) {
|
if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) {
|
||||||
cmcf->phase_engine.location_rewrite_index = n;
|
cmcf->phase_engine.location_rewrite_index = n;
|
||||||
}
|
}
|
||||||
checker = ngx_http_core_generic_phase;
|
checker = ngx_http_core_rewrite_phase;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1254,14 +1254,17 @@ ngx_http_script_return_code(ngx_http_script_engine_t *e)
|
|||||||
|
|
||||||
code = (ngx_http_script_return_code_t *) e->ip;
|
code = (ngx_http_script_return_code_t *) e->ip;
|
||||||
|
|
||||||
e->status = code->status;
|
if (code->status < NGX_HTTP_BAD_REQUEST
|
||||||
|
|| code->text.value.len
|
||||||
if (code->status == NGX_HTTP_NO_CONTENT) {
|
|| code->text.lengths)
|
||||||
e->request->header_only = 1;
|
{
|
||||||
e->request->zero_body = 1;
|
e->status = ngx_http_send_response(e->request, code->status, NULL,
|
||||||
|
&code->text);
|
||||||
|
} else {
|
||||||
|
e->status = code->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
e->ip += sizeof(ngx_http_script_return_code_t) - sizeof(uintptr_t);
|
e->ip = ngx_http_script_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
ngx_http_script_code_pt code;
|
ngx_http_script_code_pt code;
|
||||||
uintptr_t status;
|
uintptr_t status;
|
||||||
uintptr_t null;
|
ngx_http_complex_value_t text;
|
||||||
} ngx_http_script_return_code_t;
|
} ngx_http_script_return_code_t;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user