Downgrade auf Nginx 1.13.3
This commit is contained in:
@@ -7,7 +7,7 @@ if [ $USE_PCRE = YES -o $PCRE != NONE ]; then
|
|||||||
. auto/lib/pcre/conf
|
. auto/lib/pcre/conf
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ $USE_PCRE = DISABLED -a $HTTP = YES -a $HTTP_REWRITE = YES ]; then
|
if [ $USE_PCRE = DISABLED -a $HTTP_REWRITE = YES ]; then
|
||||||
|
|
||||||
cat << END
|
cat << END
|
||||||
|
|
||||||
|
|||||||
22
auto/modules
22
auto/modules
@@ -506,28 +506,6 @@ if [ $HTTP = YES ]; then
|
|||||||
. auto/module
|
. auto/module
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $HTTP_MIRROR = YES ]; then
|
|
||||||
ngx_module_name=ngx_http_mirror_module
|
|
||||||
ngx_module_incs=
|
|
||||||
ngx_module_deps=
|
|
||||||
ngx_module_srcs=src/http/modules/ngx_http_mirror_module.c
|
|
||||||
ngx_module_libs=
|
|
||||||
ngx_module_link=$HTTP_MIRROR
|
|
||||||
|
|
||||||
. auto/module
|
|
||||||
fi
|
|
||||||
|
|
||||||
if :; then
|
|
||||||
ngx_module_name=ngx_http_try_files_module
|
|
||||||
ngx_module_incs=
|
|
||||||
ngx_module_deps=
|
|
||||||
ngx_module_srcs=src/http/modules/ngx_http_try_files_module.c
|
|
||||||
ngx_module_libs=
|
|
||||||
ngx_module_link=YES
|
|
||||||
|
|
||||||
. auto/module
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $HTTP_AUTH_REQUEST = YES ]; then
|
if [ $HTTP_AUTH_REQUEST = YES ]; then
|
||||||
ngx_module_name=ngx_http_auth_request_module
|
ngx_module_name=ngx_http_auth_request_module
|
||||||
ngx_module_incs=
|
ngx_module_incs=
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ HTTP_DAV=NO
|
|||||||
HTTP_ACCESS=YES
|
HTTP_ACCESS=YES
|
||||||
HTTP_AUTH_BASIC=YES
|
HTTP_AUTH_BASIC=YES
|
||||||
HTTP_AUTH_REQUEST=NO
|
HTTP_AUTH_REQUEST=NO
|
||||||
HTTP_MIRROR=YES
|
|
||||||
HTTP_USERID=YES
|
HTTP_USERID=YES
|
||||||
HTTP_SLICE=NO
|
HTTP_SLICE=NO
|
||||||
HTTP_AUTOINDEX=YES
|
HTTP_AUTOINDEX=YES
|
||||||
@@ -250,7 +249,6 @@ $0: warning: the \"--with-ipv6\" option is deprecated"
|
|||||||
--without-http_userid_module) HTTP_USERID=NO ;;
|
--without-http_userid_module) HTTP_USERID=NO ;;
|
||||||
--without-http_access_module) HTTP_ACCESS=NO ;;
|
--without-http_access_module) HTTP_ACCESS=NO ;;
|
||||||
--without-http_auth_basic_module) HTTP_AUTH_BASIC=NO ;;
|
--without-http_auth_basic_module) HTTP_AUTH_BASIC=NO ;;
|
||||||
--without-http_mirror_module) HTTP_MIRROR=NO ;;
|
|
||||||
--without-http_autoindex_module) HTTP_AUTOINDEX=NO ;;
|
--without-http_autoindex_module) HTTP_AUTOINDEX=NO ;;
|
||||||
--without-http_status_module) HTTP_STATUS=NO ;;
|
--without-http_status_module) HTTP_STATUS=NO ;;
|
||||||
--without-http_geo_module) HTTP_GEO=NO ;;
|
--without-http_geo_module) HTTP_GEO=NO ;;
|
||||||
@@ -460,7 +458,6 @@ cat << END
|
|||||||
--without-http_userid_module disable ngx_http_userid_module
|
--without-http_userid_module disable ngx_http_userid_module
|
||||||
--without-http_access_module disable ngx_http_access_module
|
--without-http_access_module disable ngx_http_access_module
|
||||||
--without-http_auth_basic_module disable ngx_http_auth_basic_module
|
--without-http_auth_basic_module disable ngx_http_auth_basic_module
|
||||||
--without-http_mirror_module disable ngx_http_mirror_module
|
|
||||||
--without-http_autoindex_module disable ngx_http_autoindex_module
|
--without-http_autoindex_module disable ngx_http_autoindex_module
|
||||||
--without-http_geo_module disable ngx_http_geo_module
|
--without-http_geo_module disable ngx_http_geo_module
|
||||||
--without-http_map_module disable ngx_http_map_module
|
--without-http_map_module disable ngx_http_map_module
|
||||||
|
|||||||
@@ -273,12 +273,6 @@ main(int argc, char *const *argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* ngx_slab_sizes_init() requires ngx_pagesize set in ngx_os_init()
|
|
||||||
*/
|
|
||||||
|
|
||||||
ngx_slab_sizes_init();
|
|
||||||
|
|
||||||
if (ngx_add_inherited_sockets(&init_cycle) != NGX_OK) {
|
if (ngx_add_inherited_sockets(&init_cycle) != NGX_OK) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
#define _NGINX_H_INCLUDED_
|
#define _NGINX_H_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
#define nginx_version 1013004
|
#define nginx_version 1013003
|
||||||
#define NGINX_VERSION "1.13.4"
|
#define NGINX_VERSION "1.13.3"
|
||||||
#define NGINX_VER "nginx/" NGINX_VERSION
|
#define NGINX_VER "nginx/" NGINX_VERSION
|
||||||
|
|
||||||
#ifdef NGX_BUILD
|
#ifdef NGX_BUILD
|
||||||
|
|||||||
@@ -473,7 +473,7 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle)
|
|||||||
|
|
||||||
#if (NGX_HAVE_REUSEPORT)
|
#if (NGX_HAVE_REUSEPORT)
|
||||||
|
|
||||||
if (ls[i].reuseport && !ngx_test_config) {
|
if (ls[i].reuseport) {
|
||||||
int reuseport;
|
int reuseport;
|
||||||
|
|
||||||
reuseport = 1;
|
reuseport = 1;
|
||||||
@@ -483,7 +483,7 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle)
|
|||||||
== -1)
|
== -1)
|
||||||
{
|
{
|
||||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||||
"setsockopt(SO_REUSEPORT) %V failed",
|
"setsockopt(SO_REUSEPORT) %V failed, ignored",
|
||||||
&ls[i].addr_text);
|
&ls[i].addr_text);
|
||||||
|
|
||||||
if (ngx_close_socket(s) == -1) {
|
if (ngx_close_socket(s) == -1) {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ ngx_parse_http_time(u_char *value, size_t len)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
day = (*p - '0') * 10 + (*(p + 1) - '0');
|
day = (*p - '0') * 10 + *(p + 1) - '0';
|
||||||
p += 2;
|
p += 2;
|
||||||
|
|
||||||
if (*p == ' ') {
|
if (*p == ' ') {
|
||||||
@@ -132,7 +132,7 @@ ngx_parse_http_time(u_char *value, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
year = (*p - '0') * 1000 + (*(p + 1) - '0') * 100
|
year = (*p - '0') * 1000 + (*(p + 1) - '0') * 100
|
||||||
+ (*(p + 2) - '0') * 10 + (*(p + 3) - '0');
|
+ (*(p + 2) - '0') * 10 + *(p + 3) - '0';
|
||||||
p += 4;
|
p += 4;
|
||||||
|
|
||||||
} else if (fmt == rfc850) {
|
} else if (fmt == rfc850) {
|
||||||
@@ -140,7 +140,7 @@ ngx_parse_http_time(u_char *value, size_t len)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
year = (*p - '0') * 10 + (*(p + 1) - '0');
|
year = (*p - '0') * 10 + *(p + 1) - '0';
|
||||||
year += (year < 70) ? 2000 : 1900;
|
year += (year < 70) ? 2000 : 1900;
|
||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ ngx_parse_http_time(u_char *value, size_t len)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
day = day * 10 + (*p++ - '0');
|
day = day * 10 + *p++ - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end - p < 14) {
|
if (end - p < 14) {
|
||||||
@@ -177,7 +177,7 @@ ngx_parse_http_time(u_char *value, size_t len)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
hour = (*p - '0') * 10 + (*(p + 1) - '0');
|
hour = (*p - '0') * 10 + *(p + 1) - '0';
|
||||||
p += 2;
|
p += 2;
|
||||||
|
|
||||||
if (*p++ != ':') {
|
if (*p++ != ':') {
|
||||||
@@ -188,7 +188,7 @@ ngx_parse_http_time(u_char *value, size_t len)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
min = (*p - '0') * 10 + (*(p + 1) - '0');
|
min = (*p - '0') * 10 + *(p + 1) - '0';
|
||||||
p += 2;
|
p += 2;
|
||||||
|
|
||||||
if (*p++ != ':') {
|
if (*p++ != ':') {
|
||||||
@@ -199,7 +199,7 @@ ngx_parse_http_time(u_char *value, size_t len)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
sec = (*p - '0') * 10 + (*(p + 1) - '0');
|
sec = (*p - '0') * 10 + *(p + 1) - '0';
|
||||||
|
|
||||||
if (fmt == isoc) {
|
if (fmt == isoc) {
|
||||||
p += 2;
|
p += 2;
|
||||||
@@ -216,7 +216,7 @@ ngx_parse_http_time(u_char *value, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
year = (*p - '0') * 1000 + (*(p + 1) - '0') * 100
|
year = (*p - '0') * 1000 + (*(p + 1) - '0') * 100
|
||||||
+ (*(p + 2) - '0') * 10 + (*(p + 3) - '0');
|
+ (*(p + 2) - '0') * 10 + *(p + 3) - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hour > 23 || min > 59 || sec > 59) {
|
if (hour > 23 || min > 59 || sec > 59) {
|
||||||
|
|||||||
@@ -82,19 +82,6 @@ static ngx_uint_t ngx_slab_exact_size;
|
|||||||
static ngx_uint_t ngx_slab_exact_shift;
|
static ngx_uint_t ngx_slab_exact_shift;
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ngx_slab_sizes_init(void)
|
|
||||||
{
|
|
||||||
ngx_uint_t n;
|
|
||||||
|
|
||||||
ngx_slab_max_size = ngx_pagesize / 2;
|
|
||||||
ngx_slab_exact_size = ngx_pagesize / (8 * sizeof(uintptr_t));
|
|
||||||
for (n = ngx_slab_exact_size; n >>= 1; ngx_slab_exact_shift++) {
|
|
||||||
/* void */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ngx_slab_init(ngx_slab_pool_t *pool)
|
ngx_slab_init(ngx_slab_pool_t *pool)
|
||||||
{
|
{
|
||||||
@@ -104,6 +91,16 @@ ngx_slab_init(ngx_slab_pool_t *pool)
|
|||||||
ngx_uint_t i, n, pages;
|
ngx_uint_t i, n, pages;
|
||||||
ngx_slab_page_t *slots, *page;
|
ngx_slab_page_t *slots, *page;
|
||||||
|
|
||||||
|
/* STUB */
|
||||||
|
if (ngx_slab_max_size == 0) {
|
||||||
|
ngx_slab_max_size = ngx_pagesize / 2;
|
||||||
|
ngx_slab_exact_size = ngx_pagesize / (8 * sizeof(uintptr_t));
|
||||||
|
for (n = ngx_slab_exact_size; n >>= 1; ngx_slab_exact_shift++) {
|
||||||
|
/* void */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**/
|
||||||
|
|
||||||
pool->min_size = (size_t) 1 << pool->min_shift;
|
pool->min_size = (size_t) 1 << pool->min_shift;
|
||||||
|
|
||||||
slots = ngx_slab_slots(pool);
|
slots = ngx_slab_slots(pool);
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ typedef struct {
|
|||||||
} ngx_slab_pool_t;
|
} ngx_slab_pool_t;
|
||||||
|
|
||||||
|
|
||||||
void ngx_slab_sizes_init(void);
|
|
||||||
void ngx_slab_init(ngx_slab_pool_t *pool);
|
void ngx_slab_init(ngx_slab_pool_t *pool);
|
||||||
void *ngx_slab_alloc(ngx_slab_pool_t *pool, size_t size);
|
void *ngx_slab_alloc(ngx_slab_pool_t *pool, size_t size);
|
||||||
void *ngx_slab_alloc_locked(ngx_slab_pool_t *pool, size_t size);
|
void *ngx_slab_alloc_locked(ngx_slab_pool_t *pool, size_t size);
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args)
|
|||||||
slen = (size_t) -1;
|
slen = (size_t) -1;
|
||||||
|
|
||||||
while (*fmt >= '0' && *fmt <= '9') {
|
while (*fmt >= '0' && *fmt <= '9') {
|
||||||
width = width * 10 + (*fmt++ - '0');
|
width = width * 10 + *fmt++ - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args)
|
|||||||
fmt++;
|
fmt++;
|
||||||
|
|
||||||
while (*fmt >= '0' && *fmt <= '9') {
|
while (*fmt >= '0' && *fmt <= '9') {
|
||||||
frac_width = frac_width * 10 + (*fmt++ - '0');
|
frac_width = frac_width * 10 + *fmt++ - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -1655,7 +1655,7 @@ ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type)
|
|||||||
state = sw_usual;
|
state = sw_usual;
|
||||||
|
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
ch = (u_char) ((decoded << 4) + (ch - '0'));
|
ch = (u_char) ((decoded << 4) + ch - '0');
|
||||||
|
|
||||||
if (type & NGX_UNESCAPE_REDIRECT) {
|
if (type & NGX_UNESCAPE_REDIRECT) {
|
||||||
if (ch > '%' && ch < 0x7f) {
|
if (ch > '%' && ch < 0x7f) {
|
||||||
@@ -1675,7 +1675,7 @@ ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type)
|
|||||||
|
|
||||||
c = (u_char) (ch | 0x20);
|
c = (u_char) (ch | 0x20);
|
||||||
if (c >= 'a' && c <= 'f') {
|
if (c >= 'a' && c <= 'f') {
|
||||||
ch = (u_char) ((decoded << 4) + (c - 'a') + 10);
|
ch = (u_char) ((decoded << 4) + c - 'a' + 10);
|
||||||
|
|
||||||
if (type & NGX_UNESCAPE_URI) {
|
if (type & NGX_UNESCAPE_URI) {
|
||||||
if (ch == '?') {
|
if (ch == '?') {
|
||||||
|
|||||||
@@ -3128,7 +3128,7 @@ ngx_ssl_session_ticket_keys(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_array_t *paths)
|
|||||||
{
|
{
|
||||||
if (paths) {
|
if (paths) {
|
||||||
ngx_log_error(NGX_LOG_WARN, ssl->log, 0,
|
ngx_log_error(NGX_LOG_WARN, ssl->log, 0,
|
||||||
"\"ssl_session_ticket_key\" ignored, not supported");
|
"\"ssl_session_ticket_keys\" ignored, not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
|
|||||||
@@ -1486,7 +1486,7 @@ ngx_ssl_ocsp_parse_status_line(ngx_ssl_ocsp_ctx_t *ctx)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->code = ctx->code * 10 + (ch - '0');
|
ctx->code = ctx->code * 10 + ch - '0';
|
||||||
|
|
||||||
if (++ctx->count == 3) {
|
if (++ctx->count == 3) {
|
||||||
state = sw_space_after_status;
|
state = sw_space_after_status;
|
||||||
|
|||||||
@@ -123,8 +123,6 @@ ngx_http_addition_header_filter(ngx_http_request_t *r)
|
|||||||
ngx_http_clear_accept_ranges(r);
|
ngx_http_clear_accept_ranges(r);
|
||||||
ngx_http_weak_etag(r);
|
ngx_http_weak_etag(r);
|
||||||
|
|
||||||
r->preserve_body = 1;
|
|
||||||
|
|
||||||
return ngx_http_next_header_filter(r);
|
return ngx_http_next_header_filter(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ typedef struct {
|
|||||||
} ngx_http_modern_browser_t;
|
} ngx_http_modern_browser_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ngx_str_t name;
|
||||||
|
ngx_http_get_variable_pt handler;
|
||||||
|
uintptr_t data;
|
||||||
|
} ngx_http_browser_variable_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ngx_array_t *modern_browsers;
|
ngx_array_t *modern_browsers;
|
||||||
ngx_array_t *ancient_browsers;
|
ngx_array_t *ancient_browsers;
|
||||||
@@ -56,7 +63,7 @@ static ngx_int_t ngx_http_browser_variable(ngx_http_request_t *r,
|
|||||||
static ngx_uint_t ngx_http_browser(ngx_http_request_t *r,
|
static ngx_uint_t ngx_http_browser(ngx_http_request_t *r,
|
||||||
ngx_http_browser_conf_t *cf);
|
ngx_http_browser_conf_t *cf);
|
||||||
|
|
||||||
static ngx_int_t ngx_http_browser_add_variables(ngx_conf_t *cf);
|
static ngx_int_t ngx_http_browser_add_variable(ngx_conf_t *cf);
|
||||||
static void *ngx_http_browser_create_conf(ngx_conf_t *cf);
|
static void *ngx_http_browser_create_conf(ngx_conf_t *cf);
|
||||||
static char *ngx_http_browser_merge_conf(ngx_conf_t *cf, void *parent,
|
static char *ngx_http_browser_merge_conf(ngx_conf_t *cf, void *parent,
|
||||||
void *child);
|
void *child);
|
||||||
@@ -107,7 +114,7 @@ static ngx_command_t ngx_http_browser_commands[] = {
|
|||||||
|
|
||||||
|
|
||||||
static ngx_http_module_t ngx_http_browser_module_ctx = {
|
static ngx_http_module_t ngx_http_browser_module_ctx = {
|
||||||
ngx_http_browser_add_variables, /* preconfiguration */
|
ngx_http_browser_add_variable, /* preconfiguration */
|
||||||
NULL, /* postconfiguration */
|
NULL, /* postconfiguration */
|
||||||
|
|
||||||
NULL, /* create main configuration */
|
NULL, /* create main configuration */
|
||||||
@@ -211,18 +218,13 @@ static ngx_http_modern_browser_mask_t ngx_http_modern_browser_masks[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static ngx_http_variable_t ngx_http_browser_vars[] = {
|
static ngx_http_browser_variable_t ngx_http_browsers[] = {
|
||||||
|
{ ngx_string("msie"), ngx_http_msie_variable, 0 },
|
||||||
{ ngx_string("msie"), NULL, ngx_http_msie_variable,
|
{ ngx_string("modern_browser"), ngx_http_browser_variable,
|
||||||
0, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
NGX_HTTP_MODERN_BROWSER },
|
||||||
|
{ ngx_string("ancient_browser"), ngx_http_browser_variable,
|
||||||
{ ngx_string("modern_browser"), NULL, ngx_http_browser_variable,
|
NGX_HTTP_ANCIENT_BROWSER },
|
||||||
NGX_HTTP_MODERN_BROWSER, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
{ ngx_null_string, NULL, 0 }
|
||||||
|
|
||||||
{ ngx_string("ancient_browser"), NULL, ngx_http_browser_variable,
|
|
||||||
NGX_HTTP_ANCIENT_BROWSER, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
|
||||||
|
|
||||||
ngx_http_null_variable
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -395,19 +397,20 @@ ngx_http_msie_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
|||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
ngx_http_browser_add_variables(ngx_conf_t *cf)
|
ngx_http_browser_add_variable(ngx_conf_t *cf)
|
||||||
{
|
{
|
||||||
ngx_http_variable_t *var, *v;
|
ngx_http_browser_variable_t *var;
|
||||||
|
ngx_http_variable_t *v;
|
||||||
|
|
||||||
for (v = ngx_http_browser_vars; v->name.len; v++) {
|
for (var = ngx_http_browsers; var->name.len; var++) {
|
||||||
|
|
||||||
var = ngx_http_add_variable(cf, &v->name, v->flags);
|
v = ngx_http_add_variable(cf, &var->name, NGX_HTTP_VAR_CHANGEABLE);
|
||||||
if (var == NULL) {
|
if (v == NULL) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
var->get_handler = v->get_handler;
|
v->get_handler = var->handler;
|
||||||
var->data = v->data;
|
v->data = var->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
|
|||||||
@@ -631,7 +631,7 @@ static ngx_http_variable_t ngx_http_fastcgi_vars[] = {
|
|||||||
ngx_http_fastcgi_path_info_variable, 0,
|
ngx_http_fastcgi_path_info_variable, 0,
|
||||||
NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ static ngx_http_variable_t ngx_http_geoip_vars[] = {
|
|||||||
ngx_http_geoip_city_int_variable,
|
ngx_http_geoip_city_int_variable,
|
||||||
offsetof(GeoIPRecord, area_code), 0, 0 },
|
offsetof(GeoIPRecord, area_code), 0, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,264 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* Copyright (C) Roman Arutyunyan
|
|
||||||
* Copyright (C) Nginx, Inc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <ngx_config.h>
|
|
||||||
#include <ngx_core.h>
|
|
||||||
#include <ngx_http.h>
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
ngx_array_t *mirror;
|
|
||||||
ngx_flag_t request_body;
|
|
||||||
} ngx_http_mirror_loc_conf_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
ngx_int_t status;
|
|
||||||
} ngx_http_mirror_ctx_t;
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t ngx_http_mirror_handler(ngx_http_request_t *r);
|
|
||||||
static void ngx_http_mirror_body_handler(ngx_http_request_t *r);
|
|
||||||
static ngx_int_t ngx_http_mirror_handler_internal(ngx_http_request_t *r);
|
|
||||||
static void *ngx_http_mirror_create_loc_conf(ngx_conf_t *cf);
|
|
||||||
static char *ngx_http_mirror_merge_loc_conf(ngx_conf_t *cf, void *parent,
|
|
||||||
void *child);
|
|
||||||
static char *ngx_http_mirror(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
||||||
static ngx_int_t ngx_http_mirror_init(ngx_conf_t *cf);
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_command_t ngx_http_mirror_commands[] = {
|
|
||||||
|
|
||||||
{ ngx_string("mirror"),
|
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
||||||
ngx_http_mirror,
|
|
||||||
NGX_HTTP_LOC_CONF_OFFSET,
|
|
||||||
0,
|
|
||||||
NULL },
|
|
||||||
|
|
||||||
{ ngx_string("mirror_request_body"),
|
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
||||||
ngx_conf_set_flag_slot,
|
|
||||||
NGX_HTTP_LOC_CONF_OFFSET,
|
|
||||||
offsetof(ngx_http_mirror_loc_conf_t, request_body),
|
|
||||||
NULL },
|
|
||||||
|
|
||||||
ngx_null_command
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_http_module_t ngx_http_mirror_module_ctx = {
|
|
||||||
NULL, /* preconfiguration */
|
|
||||||
ngx_http_mirror_init, /* postconfiguration */
|
|
||||||
|
|
||||||
NULL, /* create main configuration */
|
|
||||||
NULL, /* init main configuration */
|
|
||||||
|
|
||||||
NULL, /* create server configuration */
|
|
||||||
NULL, /* merge server configuration */
|
|
||||||
|
|
||||||
ngx_http_mirror_create_loc_conf, /* create location configuration */
|
|
||||||
ngx_http_mirror_merge_loc_conf /* merge location configuration */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
ngx_module_t ngx_http_mirror_module = {
|
|
||||||
NGX_MODULE_V1,
|
|
||||||
&ngx_http_mirror_module_ctx, /* module context */
|
|
||||||
ngx_http_mirror_commands, /* module directives */
|
|
||||||
NGX_HTTP_MODULE, /* module type */
|
|
||||||
NULL, /* init master */
|
|
||||||
NULL, /* init module */
|
|
||||||
NULL, /* init process */
|
|
||||||
NULL, /* init thread */
|
|
||||||
NULL, /* exit thread */
|
|
||||||
NULL, /* exit process */
|
|
||||||
NULL, /* exit master */
|
|
||||||
NGX_MODULE_V1_PADDING
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
|
||||||
ngx_http_mirror_handler(ngx_http_request_t *r)
|
|
||||||
{
|
|
||||||
ngx_int_t rc;
|
|
||||||
ngx_http_mirror_ctx_t *ctx;
|
|
||||||
ngx_http_mirror_loc_conf_t *mlcf;
|
|
||||||
|
|
||||||
if (r != r->main) {
|
|
||||||
return NGX_DECLINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
mlcf = ngx_http_get_module_loc_conf(r, ngx_http_mirror_module);
|
|
||||||
|
|
||||||
if (mlcf->mirror == NULL) {
|
|
||||||
return NGX_DECLINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "mirror handler");
|
|
||||||
|
|
||||||
if (mlcf->request_body) {
|
|
||||||
ctx = ngx_http_get_module_ctx(r, ngx_http_mirror_module);
|
|
||||||
|
|
||||||
if (ctx) {
|
|
||||||
return ctx->status;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_mirror_ctx_t));
|
|
||||||
if (ctx == NULL) {
|
|
||||||
return NGX_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->status = NGX_DONE;
|
|
||||||
|
|
||||||
ngx_http_set_ctx(r, ctx, ngx_http_mirror_module);
|
|
||||||
|
|
||||||
rc = ngx_http_read_client_request_body(r, ngx_http_mirror_body_handler);
|
|
||||||
if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_http_finalize_request(r, NGX_DONE);
|
|
||||||
return NGX_DONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ngx_http_mirror_handler_internal(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
ngx_http_mirror_body_handler(ngx_http_request_t *r)
|
|
||||||
{
|
|
||||||
ngx_http_mirror_ctx_t *ctx;
|
|
||||||
|
|
||||||
ctx = ngx_http_get_module_ctx(r, ngx_http_mirror_module);
|
|
||||||
|
|
||||||
ctx->status = ngx_http_mirror_handler_internal(r);
|
|
||||||
|
|
||||||
r->preserve_body = 1;
|
|
||||||
|
|
||||||
r->write_event_handler = ngx_http_core_run_phases;
|
|
||||||
ngx_http_core_run_phases(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
|
||||||
ngx_http_mirror_handler_internal(ngx_http_request_t *r)
|
|
||||||
{
|
|
||||||
ngx_str_t *name;
|
|
||||||
ngx_uint_t i;
|
|
||||||
ngx_http_request_t *sr;
|
|
||||||
ngx_http_mirror_loc_conf_t *mlcf;
|
|
||||||
|
|
||||||
mlcf = ngx_http_get_module_loc_conf(r, ngx_http_mirror_module);
|
|
||||||
|
|
||||||
name = mlcf->mirror->elts;
|
|
||||||
|
|
||||||
for (i = 0; i < mlcf->mirror->nelts; i++) {
|
|
||||||
if (ngx_http_subrequest(r, &name[i], &r->args, &sr, NULL,
|
|
||||||
NGX_HTTP_SUBREQUEST_BACKGROUND)
|
|
||||||
!= NGX_OK)
|
|
||||||
{
|
|
||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
sr->header_only = 1;
|
|
||||||
sr->method = r->method;
|
|
||||||
sr->method_name = r->method_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NGX_DECLINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void *
|
|
||||||
ngx_http_mirror_create_loc_conf(ngx_conf_t *cf)
|
|
||||||
{
|
|
||||||
ngx_http_mirror_loc_conf_t *mlcf;
|
|
||||||
|
|
||||||
mlcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_mirror_loc_conf_t));
|
|
||||||
if (mlcf == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
mlcf->mirror = NGX_CONF_UNSET_PTR;
|
|
||||||
mlcf->request_body = NGX_CONF_UNSET;
|
|
||||||
|
|
||||||
return mlcf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char *
|
|
||||||
ngx_http_mirror_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|
||||||
{
|
|
||||||
ngx_http_mirror_loc_conf_t *prev = parent;
|
|
||||||
ngx_http_mirror_loc_conf_t *conf = child;
|
|
||||||
|
|
||||||
ngx_conf_merge_ptr_value(conf->mirror, prev->mirror, NULL);
|
|
||||||
ngx_conf_merge_value(conf->request_body, prev->request_body, 1);
|
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char *
|
|
||||||
ngx_http_mirror(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
||||||
{
|
|
||||||
ngx_http_mirror_loc_conf_t *mlcf = conf;
|
|
||||||
|
|
||||||
ngx_str_t *value, *s;
|
|
||||||
|
|
||||||
value = cf->args->elts;
|
|
||||||
|
|
||||||
if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
||||||
if (mlcf->mirror != NGX_CONF_UNSET_PTR) {
|
|
||||||
return "is duplicate";
|
|
||||||
}
|
|
||||||
|
|
||||||
mlcf->mirror = NULL;
|
|
||||||
return NGX_CONF_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mlcf->mirror == NULL) {
|
|
||||||
return "is duplicate";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mlcf->mirror == NGX_CONF_UNSET_PTR) {
|
|
||||||
mlcf->mirror = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
|
|
||||||
if (mlcf->mirror == NULL) {
|
|
||||||
return NGX_CONF_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s = ngx_array_push(mlcf->mirror);
|
|
||||||
if (s == NULL) {
|
|
||||||
return NGX_CONF_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
*s = value[1];
|
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
|
||||||
ngx_http_mirror_init(ngx_conf_t *cf)
|
|
||||||
{
|
|
||||||
ngx_http_handler_pt *h;
|
|
||||||
ngx_http_core_main_conf_t *cmcf;
|
|
||||||
|
|
||||||
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
|
||||||
|
|
||||||
h = ngx_array_push(&cmcf->phases[NGX_HTTP_PRECONTENT_PHASE].handlers);
|
|
||||||
if (h == NULL) {
|
|
||||||
return NGX_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
*h = ngx_http_mirror_handler;
|
|
||||||
|
|
||||||
return NGX_OK;
|
|
||||||
}
|
|
||||||
@@ -829,7 +829,7 @@ static ngx_http_variable_t ngx_http_proxy_vars[] = {
|
|||||||
ngx_http_proxy_internal_chunked_variable, 0,
|
ngx_http_proxy_internal_chunked_variable, 0,
|
||||||
NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx,
|
|||||||
return NGX_HTTP_RANGE_NOT_SATISFIABLE;
|
return NGX_HTTP_RANGE_NOT_SATISFIABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = start * 10 + (*p++ - '0');
|
start = start * 10 + *p++ - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*p == ' ') { p++; }
|
while (*p == ' ') { p++; }
|
||||||
@@ -345,7 +345,7 @@ ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx,
|
|||||||
return NGX_HTTP_RANGE_NOT_SATISFIABLE;
|
return NGX_HTTP_RANGE_NOT_SATISFIABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
end = end * 10 + (*p++ - '0');
|
end = end * 10 + *p++ - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*p == ' ') { p++; }
|
while (*p == ' ') { p++; }
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ static ngx_http_variable_t ngx_http_realip_vars[] = {
|
|||||||
{ ngx_string("realip_remote_port"), NULL,
|
{ ngx_string("realip_remote_port"), NULL,
|
||||||
ngx_http_realip_remote_port_variable, 0, 0, 0 },
|
ngx_http_realip_remote_port_variable, 0, 0, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ typedef struct {
|
|||||||
} ngx_http_referer_conf_t;
|
} ngx_http_referer_conf_t;
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t ngx_http_referer_add_variables(ngx_conf_t *cf);
|
|
||||||
static void * ngx_http_referer_create_conf(ngx_conf_t *cf);
|
static void * ngx_http_referer_create_conf(ngx_conf_t *cf);
|
||||||
static char * ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent,
|
static char * ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent,
|
||||||
void *child);
|
void *child);
|
||||||
@@ -78,7 +77,7 @@ static ngx_command_t ngx_http_referer_commands[] = {
|
|||||||
|
|
||||||
|
|
||||||
static ngx_http_module_t ngx_http_referer_module_ctx = {
|
static ngx_http_module_t ngx_http_referer_module_ctx = {
|
||||||
ngx_http_referer_add_variables, /* preconfiguration */
|
NULL, /* preconfiguration */
|
||||||
NULL, /* postconfiguration */
|
NULL, /* postconfiguration */
|
||||||
|
|
||||||
NULL, /* create main configuration */
|
NULL, /* create main configuration */
|
||||||
@@ -108,9 +107,6 @@ ngx_module_t ngx_http_referer_module = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static ngx_str_t ngx_http_invalid_referer_name = ngx_string("invalid_referer");
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
ngx_http_referer_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
ngx_http_referer_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||||
uintptr_t data)
|
uintptr_t data)
|
||||||
@@ -267,23 +263,6 @@ valid:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
|
||||||
ngx_http_referer_add_variables(ngx_conf_t *cf)
|
|
||||||
{
|
|
||||||
ngx_http_variable_t *var;
|
|
||||||
|
|
||||||
var = ngx_http_add_variable(cf, &ngx_http_invalid_referer_name,
|
|
||||||
NGX_HTTP_VAR_CHANGEABLE);
|
|
||||||
if (var == NULL) {
|
|
||||||
return NGX_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
var->get_handler = ngx_http_referer_variable;
|
|
||||||
|
|
||||||
return NGX_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
ngx_http_referer_create_conf(ngx_conf_t *cf)
|
ngx_http_referer_create_conf(ngx_conf_t *cf)
|
||||||
{
|
{
|
||||||
@@ -474,8 +453,18 @@ ngx_http_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
ngx_http_referer_conf_t *rlcf = conf;
|
ngx_http_referer_conf_t *rlcf = conf;
|
||||||
|
|
||||||
u_char *p;
|
u_char *p;
|
||||||
ngx_str_t *value, uri;
|
ngx_str_t *value, uri, name;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
|
ngx_http_variable_t *var;
|
||||||
|
|
||||||
|
ngx_str_set(&name, "invalid_referer");
|
||||||
|
|
||||||
|
var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
|
||||||
|
if (var == NULL) {
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
var->get_handler = ngx_http_referer_variable;
|
||||||
|
|
||||||
if (rlcf->keys == NULL) {
|
if (rlcf->keys == NULL) {
|
||||||
rlcf->keys = ngx_pcalloc(cf->temp_pool, sizeof(ngx_hash_keys_arrays_t));
|
rlcf->keys = ngx_pcalloc(cf->temp_pool, sizeof(ngx_hash_keys_arrays_t));
|
||||||
|
|||||||
@@ -190,8 +190,6 @@ ngx_http_slice_header_filter(ngx_http_request_t *r)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->preserve_body = 1;
|
|
||||||
|
|
||||||
if (r->headers_out.status == NGX_HTTP_PARTIAL_CONTENT) {
|
if (r->headers_out.status == NGX_HTTP_PARTIAL_CONTENT) {
|
||||||
if (ctx->start + (off_t) slcf->size <= r->headers_out.content_offset) {
|
if (ctx->start + (off_t) slcf->size <= r->headers_out.content_offset) {
|
||||||
ctx->start = slcf->size
|
ctx->start = slcf->size
|
||||||
@@ -319,7 +317,7 @@ ngx_http_slice_parse_content_range(ngx_http_request_t *r,
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = start * 10 + (*p++ - '0');
|
start = start * 10 + *p++ - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*p == ' ') { p++; }
|
while (*p == ' ') { p++; }
|
||||||
@@ -339,7 +337,7 @@ ngx_http_slice_parse_content_range(ngx_http_request_t *r,
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
end = end * 10 + (*p++ - '0');
|
end = end * 10 + *p++ - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
end++;
|
end++;
|
||||||
@@ -364,7 +362,7 @@ ngx_http_slice_parse_content_range(ngx_http_request_t *r,
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
complete_length = complete_length * 10 + (*p++ - '0');
|
complete_length = complete_length * 10 + *p++ - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -481,7 +479,7 @@ ngx_http_slice_get_start(ngx_http_request_t *r)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = start * 10 + (*p++ - '0');
|
start = start * 10 + *p++ - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return start;
|
return start;
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ static ngx_http_variable_t ngx_http_ssi_vars[] = {
|
|||||||
{ ngx_string("date_gmt"), NULL, ngx_http_ssi_date_gmt_local_variable, 1,
|
{ ngx_string("date_gmt"), NULL, ngx_http_ssi_date_gmt_local_variable, 1,
|
||||||
NGX_HTTP_VAR_NOCACHEABLE, 0 },
|
NGX_HTTP_VAR_NOCACHEABLE, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -370,8 +370,6 @@ ngx_http_ssi_header_filter(ngx_http_request_t *r)
|
|||||||
ngx_http_clear_content_length(r);
|
ngx_http_clear_content_length(r);
|
||||||
ngx_http_clear_accept_ranges(r);
|
ngx_http_clear_accept_ranges(r);
|
||||||
|
|
||||||
r->preserve_body = 1;
|
|
||||||
|
|
||||||
if (!slcf->last_modified) {
|
if (!slcf->last_modified) {
|
||||||
ngx_http_clear_last_modified(r);
|
ngx_http_clear_last_modified(r);
|
||||||
ngx_http_clear_etag(r);
|
ngx_http_clear_etag(r);
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ static ngx_http_variable_t ngx_http_ssl_vars[] = {
|
|||||||
{ ngx_string("ssl_client_v_remain"), NULL, ngx_http_ssl_variable,
|
{ ngx_string("ssl_client_v_remain"), NULL, ngx_http_ssl_variable,
|
||||||
(uintptr_t) ngx_ssl_get_client_v_remain, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
(uintptr_t) ngx_ssl_get_client_v_remain, NGX_HTTP_VAR_CHANGEABLE, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ static ngx_http_variable_t ngx_http_stub_status_vars[] = {
|
|||||||
{ ngx_string("connections_waiting"), NULL, ngx_http_stub_status_variable,
|
{ ngx_string("connections_waiting"), NULL, ngx_http_stub_status_variable,
|
||||||
3, NGX_HTTP_VAR_NOCACHEABLE, 0 },
|
3, NGX_HTTP_VAR_NOCACHEABLE, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,404 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* Copyright (C) Igor Sysoev
|
|
||||||
* Copyright (C) Nginx, Inc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <ngx_config.h>
|
|
||||||
#include <ngx_core.h>
|
|
||||||
#include <ngx_http.h>
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
ngx_array_t *lengths;
|
|
||||||
ngx_array_t *values;
|
|
||||||
ngx_str_t name;
|
|
||||||
|
|
||||||
unsigned code:10;
|
|
||||||
unsigned test_dir:1;
|
|
||||||
} ngx_http_try_file_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
ngx_http_try_file_t *try_files;
|
|
||||||
} ngx_http_try_files_loc_conf_t;
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t ngx_http_try_files_handler(ngx_http_request_t *r);
|
|
||||||
static char *ngx_http_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
||||||
static void *ngx_http_try_files_create_loc_conf(ngx_conf_t *cf);
|
|
||||||
static ngx_int_t ngx_http_try_files_init(ngx_conf_t *cf);
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_command_t ngx_http_try_files_commands[] = {
|
|
||||||
|
|
||||||
{ ngx_string("try_files"),
|
|
||||||
NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
|
|
||||||
ngx_http_try_files,
|
|
||||||
NGX_HTTP_LOC_CONF_OFFSET,
|
|
||||||
0,
|
|
||||||
NULL },
|
|
||||||
|
|
||||||
ngx_null_command
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_http_module_t ngx_http_try_files_module_ctx = {
|
|
||||||
NULL, /* preconfiguration */
|
|
||||||
ngx_http_try_files_init, /* postconfiguration */
|
|
||||||
|
|
||||||
NULL, /* create main configuration */
|
|
||||||
NULL, /* init main configuration */
|
|
||||||
|
|
||||||
NULL, /* create server configuration */
|
|
||||||
NULL, /* merge server configuration */
|
|
||||||
|
|
||||||
ngx_http_try_files_create_loc_conf, /* create location configuration */
|
|
||||||
NULL /* merge location configuration */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
ngx_module_t ngx_http_try_files_module = {
|
|
||||||
NGX_MODULE_V1,
|
|
||||||
&ngx_http_try_files_module_ctx, /* module context */
|
|
||||||
ngx_http_try_files_commands, /* module directives */
|
|
||||||
NGX_HTTP_MODULE, /* module type */
|
|
||||||
NULL, /* init master */
|
|
||||||
NULL, /* init module */
|
|
||||||
NULL, /* init process */
|
|
||||||
NULL, /* init thread */
|
|
||||||
NULL, /* exit thread */
|
|
||||||
NULL, /* exit process */
|
|
||||||
NULL, /* exit master */
|
|
||||||
NGX_MODULE_V1_PADDING
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
|
||||||
ngx_http_try_files_handler(ngx_http_request_t *r)
|
|
||||||
{
|
|
||||||
size_t len, root, alias, reserve, allocated;
|
|
||||||
u_char *p, *name;
|
|
||||||
ngx_str_t path, args;
|
|
||||||
ngx_uint_t test_dir;
|
|
||||||
ngx_http_try_file_t *tf;
|
|
||||||
ngx_open_file_info_t of;
|
|
||||||
ngx_http_script_code_pt code;
|
|
||||||
ngx_http_script_engine_t e;
|
|
||||||
ngx_http_core_loc_conf_t *clcf;
|
|
||||||
ngx_http_script_len_code_pt lcode;
|
|
||||||
ngx_http_try_files_loc_conf_t *tlcf;
|
|
||||||
|
|
||||||
tlcf = ngx_http_get_module_loc_conf(r, ngx_http_try_files_module);
|
|
||||||
|
|
||||||
if (tlcf->try_files == NULL) {
|
|
||||||
return NGX_DECLINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
||||||
"try files handler");
|
|
||||||
|
|
||||||
allocated = 0;
|
|
||||||
root = 0;
|
|
||||||
name = NULL;
|
|
||||||
/* suppress MSVC warning */
|
|
||||||
path.data = NULL;
|
|
||||||
|
|
||||||
tf = tlcf->try_files;
|
|
||||||
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
||||||
|
|
||||||
alias = clcf->alias;
|
|
||||||
|
|
||||||
for ( ;; ) {
|
|
||||||
|
|
||||||
if (tf->lengths) {
|
|
||||||
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
|
||||||
|
|
||||||
e.ip = tf->lengths->elts;
|
|
||||||
e.request = r;
|
|
||||||
|
|
||||||
/* 1 is for terminating '\0' as in static names */
|
|
||||||
len = 1;
|
|
||||||
|
|
||||||
while (*(uintptr_t *) e.ip) {
|
|
||||||
lcode = *(ngx_http_script_len_code_pt *) e.ip;
|
|
||||||
len += lcode(&e);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
len = tf->name.len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!alias) {
|
|
||||||
reserve = len > r->uri.len ? len - r->uri.len : 0;
|
|
||||||
|
|
||||||
} else if (alias == NGX_MAX_SIZE_T_VALUE) {
|
|
||||||
reserve = len;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
reserve = len > r->uri.len - alias ? len - (r->uri.len - alias) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reserve > allocated || !allocated) {
|
|
||||||
|
|
||||||
/* 16 bytes are preallocation */
|
|
||||||
allocated = reserve + 16;
|
|
||||||
|
|
||||||
if (ngx_http_map_uri_to_path(r, &path, &root, allocated) == NULL) {
|
|
||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
name = path.data + root;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tf->values == NULL) {
|
|
||||||
|
|
||||||
/* tf->name.len includes the terminating '\0' */
|
|
||||||
|
|
||||||
ngx_memcpy(name, tf->name.data, tf->name.len);
|
|
||||||
|
|
||||||
path.len = (name + tf->name.len - 1) - path.data;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
e.ip = tf->values->elts;
|
|
||||||
e.pos = name;
|
|
||||||
e.flushed = 1;
|
|
||||||
|
|
||||||
while (*(uintptr_t *) e.ip) {
|
|
||||||
code = *(ngx_http_script_code_pt *) e.ip;
|
|
||||||
code((ngx_http_script_engine_t *) &e);
|
|
||||||
}
|
|
||||||
|
|
||||||
path.len = e.pos - path.data;
|
|
||||||
|
|
||||||
*e.pos = '\0';
|
|
||||||
|
|
||||||
if (alias && alias != NGX_MAX_SIZE_T_VALUE
|
|
||||||
&& ngx_strncmp(name, r->uri.data, alias) == 0)
|
|
||||||
{
|
|
||||||
ngx_memmove(name, name + alias, len - alias);
|
|
||||||
path.len -= alias;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test_dir = tf->test_dir;
|
|
||||||
|
|
||||||
tf++;
|
|
||||||
|
|
||||||
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
||||||
"trying to use %s: \"%s\" \"%s\"",
|
|
||||||
test_dir ? "dir" : "file", name, path.data);
|
|
||||||
|
|
||||||
if (tf->lengths == NULL && tf->name.len == 0) {
|
|
||||||
|
|
||||||
if (tf->code) {
|
|
||||||
return tf->code;
|
|
||||||
}
|
|
||||||
|
|
||||||
path.len -= root;
|
|
||||||
path.data += root;
|
|
||||||
|
|
||||||
if (path.data[0] == '@') {
|
|
||||||
(void) ngx_http_named_location(r, &path);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ngx_http_split_args(r, &path, &args);
|
|
||||||
|
|
||||||
(void) ngx_http_internal_redirect(r, &path, &args);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_http_finalize_request(r, NGX_DONE);
|
|
||||||
return NGX_DONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_memzero(&of, sizeof(ngx_open_file_info_t));
|
|
||||||
|
|
||||||
of.read_ahead = clcf->read_ahead;
|
|
||||||
of.directio = clcf->directio;
|
|
||||||
of.valid = clcf->open_file_cache_valid;
|
|
||||||
of.min_uses = clcf->open_file_cache_min_uses;
|
|
||||||
of.test_only = 1;
|
|
||||||
of.errors = clcf->open_file_cache_errors;
|
|
||||||
of.events = clcf->open_file_cache_events;
|
|
||||||
|
|
||||||
if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) {
|
|
||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
|
|
||||||
!= NGX_OK)
|
|
||||||
{
|
|
||||||
if (of.err == 0) {
|
|
||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (of.err != NGX_ENOENT
|
|
||||||
&& of.err != NGX_ENOTDIR
|
|
||||||
&& of.err != NGX_ENAMETOOLONG)
|
|
||||||
{
|
|
||||||
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
|
|
||||||
"%s \"%s\" failed", of.failed, path.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (of.is_dir != test_dir) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
path.len -= root;
|
|
||||||
path.data += root;
|
|
||||||
|
|
||||||
if (!alias) {
|
|
||||||
r->uri = path;
|
|
||||||
|
|
||||||
} else if (alias == NGX_MAX_SIZE_T_VALUE) {
|
|
||||||
if (!test_dir) {
|
|
||||||
r->uri = path;
|
|
||||||
r->add_uri_to_alias = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
name = r->uri.data;
|
|
||||||
|
|
||||||
r->uri.len = alias + path.len;
|
|
||||||
r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
|
|
||||||
if (r->uri.data == NULL) {
|
|
||||||
r->uri.len = 0;
|
|
||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = ngx_copy(r->uri.data, name, alias);
|
|
||||||
ngx_memcpy(p, path.data, path.len);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_http_set_exten(r);
|
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
||||||
"try file uri: \"%V\"", &r->uri);
|
|
||||||
|
|
||||||
return NGX_DECLINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* not reached */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char *
|
|
||||||
ngx_http_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
||||||
{
|
|
||||||
ngx_http_try_files_loc_conf_t *tlcf = conf;
|
|
||||||
|
|
||||||
ngx_str_t *value;
|
|
||||||
ngx_int_t code;
|
|
||||||
ngx_uint_t i, n;
|
|
||||||
ngx_http_try_file_t *tf;
|
|
||||||
ngx_http_script_compile_t sc;
|
|
||||||
|
|
||||||
if (tlcf->try_files) {
|
|
||||||
return "is duplicate";
|
|
||||||
}
|
|
||||||
|
|
||||||
tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
|
|
||||||
if (tf == NULL) {
|
|
||||||
return NGX_CONF_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
tlcf->try_files = tf;
|
|
||||||
|
|
||||||
value = cf->args->elts;
|
|
||||||
|
|
||||||
for (i = 0; i < cf->args->nelts - 1; i++) {
|
|
||||||
|
|
||||||
tf[i].name = value[i + 1];
|
|
||||||
|
|
||||||
if (tf[i].name.len > 0
|
|
||||||
&& tf[i].name.data[tf[i].name.len - 1] == '/'
|
|
||||||
&& i + 2 < cf->args->nelts)
|
|
||||||
{
|
|
||||||
tf[i].test_dir = 1;
|
|
||||||
tf[i].name.len--;
|
|
||||||
tf[i].name.data[tf[i].name.len] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
n = ngx_http_script_variables_count(&tf[i].name);
|
|
||||||
|
|
||||||
if (n) {
|
|
||||||
ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
||||||
|
|
||||||
sc.cf = cf;
|
|
||||||
sc.source = &tf[i].name;
|
|
||||||
sc.lengths = &tf[i].lengths;
|
|
||||||
sc.values = &tf[i].values;
|
|
||||||
sc.variables = n;
|
|
||||||
sc.complete_lengths = 1;
|
|
||||||
sc.complete_values = 1;
|
|
||||||
|
|
||||||
if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
||||||
return NGX_CONF_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/* add trailing '\0' to length */
|
|
||||||
tf[i].name.len++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tf[i - 1].name.data[0] == '=') {
|
|
||||||
|
|
||||||
code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2);
|
|
||||||
|
|
||||||
if (code == NGX_ERROR || code > 999) {
|
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
||||||
"invalid code \"%*s\"",
|
|
||||||
tf[i - 1].name.len - 1, tf[i - 1].name.data);
|
|
||||||
return NGX_CONF_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
tf[i].code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void *
|
|
||||||
ngx_http_try_files_create_loc_conf(ngx_conf_t *cf)
|
|
||||||
{
|
|
||||||
ngx_http_try_files_loc_conf_t *tlcf;
|
|
||||||
|
|
||||||
tlcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_try_files_loc_conf_t));
|
|
||||||
if (tlcf == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* set by ngx_pcalloc():
|
|
||||||
*
|
|
||||||
* tlcf->try_files = NULL;
|
|
||||||
*/
|
|
||||||
|
|
||||||
return tlcf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_int_t
|
|
||||||
ngx_http_try_files_init(ngx_conf_t *cf)
|
|
||||||
{
|
|
||||||
ngx_http_handler_pt *h;
|
|
||||||
ngx_http_core_main_conf_t *cmcf;
|
|
||||||
|
|
||||||
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
|
||||||
|
|
||||||
h = ngx_array_push(&cmcf->phases[NGX_HTTP_PRECONTENT_PHASE].handlers);
|
|
||||||
if (h == NULL) {
|
|
||||||
return NGX_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
*h = ngx_http_try_files_handler;
|
|
||||||
|
|
||||||
return NGX_OK;
|
|
||||||
}
|
|
||||||
@@ -16,8 +16,6 @@ static ngx_int_t ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone,
|
|||||||
void *data);
|
void *data);
|
||||||
static ngx_http_upstream_rr_peers_t *ngx_http_upstream_zone_copy_peers(
|
static ngx_http_upstream_rr_peers_t *ngx_http_upstream_zone_copy_peers(
|
||||||
ngx_slab_pool_t *shpool, ngx_http_upstream_srv_conf_t *uscf);
|
ngx_slab_pool_t *shpool, ngx_http_upstream_srv_conf_t *uscf);
|
||||||
static ngx_http_upstream_rr_peer_t *ngx_http_upstream_zone_copy_peer(
|
|
||||||
ngx_http_upstream_rr_peers_t *peers, ngx_http_upstream_rr_peer_t *src);
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_command_t ngx_http_upstream_zone_commands[] = {
|
static ngx_command_t ngx_http_upstream_zone_commands[] = {
|
||||||
@@ -187,7 +185,6 @@ static ngx_http_upstream_rr_peers_t *
|
|||||||
ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
||||||
ngx_http_upstream_srv_conf_t *uscf)
|
ngx_http_upstream_srv_conf_t *uscf)
|
||||||
{
|
{
|
||||||
ngx_str_t *name;
|
|
||||||
ngx_http_upstream_rr_peer_t *peer, **peerp;
|
ngx_http_upstream_rr_peer_t *peer, **peerp;
|
||||||
ngx_http_upstream_rr_peers_t *peers, *backup;
|
ngx_http_upstream_rr_peers_t *peers, *backup;
|
||||||
|
|
||||||
@@ -198,30 +195,18 @@ ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
|||||||
|
|
||||||
ngx_memcpy(peers, uscf->peer.data, sizeof(ngx_http_upstream_rr_peers_t));
|
ngx_memcpy(peers, uscf->peer.data, sizeof(ngx_http_upstream_rr_peers_t));
|
||||||
|
|
||||||
name = ngx_slab_alloc(shpool, sizeof(ngx_str_t));
|
|
||||||
if (name == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
name->data = ngx_slab_alloc(shpool, peers->name->len);
|
|
||||||
if (name->data == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_memcpy(name->data, peers->name->data, peers->name->len);
|
|
||||||
name->len = peers->name->len;
|
|
||||||
|
|
||||||
peers->name = name;
|
|
||||||
|
|
||||||
peers->shpool = shpool;
|
peers->shpool = shpool;
|
||||||
|
|
||||||
for (peerp = &peers->peer; *peerp; peerp = &peer->next) {
|
for (peerp = &peers->peer; *peerp; peerp = &peer->next) {
|
||||||
/* pool is unlocked */
|
/* pool is unlocked */
|
||||||
peer = ngx_http_upstream_zone_copy_peer(peers, *peerp);
|
peer = ngx_slab_calloc_locked(shpool,
|
||||||
|
sizeof(ngx_http_upstream_rr_peer_t));
|
||||||
if (peer == NULL) {
|
if (peer == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngx_memcpy(peer, *peerp, sizeof(ngx_http_upstream_rr_peer_t));
|
||||||
|
|
||||||
*peerp = peer;
|
*peerp = peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,17 +221,18 @@ ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
|||||||
|
|
||||||
ngx_memcpy(backup, peers->next, sizeof(ngx_http_upstream_rr_peers_t));
|
ngx_memcpy(backup, peers->next, sizeof(ngx_http_upstream_rr_peers_t));
|
||||||
|
|
||||||
backup->name = name;
|
|
||||||
|
|
||||||
backup->shpool = shpool;
|
backup->shpool = shpool;
|
||||||
|
|
||||||
for (peerp = &backup->peer; *peerp; peerp = &peer->next) {
|
for (peerp = &backup->peer; *peerp; peerp = &peer->next) {
|
||||||
/* pool is unlocked */
|
/* pool is unlocked */
|
||||||
peer = ngx_http_upstream_zone_copy_peer(backup, *peerp);
|
peer = ngx_slab_calloc_locked(shpool,
|
||||||
|
sizeof(ngx_http_upstream_rr_peer_t));
|
||||||
if (peer == NULL) {
|
if (peer == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngx_memcpy(peer, *peerp, sizeof(ngx_http_upstream_rr_peer_t));
|
||||||
|
|
||||||
*peerp = peer;
|
*peerp = peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,68 +244,3 @@ done:
|
|||||||
|
|
||||||
return peers;
|
return peers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ngx_http_upstream_rr_peer_t *
|
|
||||||
ngx_http_upstream_zone_copy_peer(ngx_http_upstream_rr_peers_t *peers,
|
|
||||||
ngx_http_upstream_rr_peer_t *src)
|
|
||||||
{
|
|
||||||
ngx_slab_pool_t *pool;
|
|
||||||
ngx_http_upstream_rr_peer_t *dst;
|
|
||||||
|
|
||||||
pool = peers->shpool;
|
|
||||||
|
|
||||||
dst = ngx_slab_calloc_locked(pool, sizeof(ngx_http_upstream_rr_peer_t));
|
|
||||||
if (dst == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src) {
|
|
||||||
ngx_memcpy(dst, src, sizeof(ngx_http_upstream_rr_peer_t));
|
|
||||||
dst->sockaddr = NULL;
|
|
||||||
dst->name.data = NULL;
|
|
||||||
dst->server.data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst->sockaddr = ngx_slab_calloc_locked(pool, NGX_SOCKADDRLEN);
|
|
||||||
if (dst->sockaddr == NULL) {
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst->name.data = ngx_slab_calloc_locked(pool, NGX_SOCKADDR_STRLEN);
|
|
||||||
if (dst->name.data == NULL) {
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src) {
|
|
||||||
ngx_memcpy(dst->sockaddr, src->sockaddr, src->socklen);
|
|
||||||
ngx_memcpy(dst->name.data, src->name.data, src->name.len);
|
|
||||||
|
|
||||||
dst->server.data = ngx_slab_alloc_locked(pool, src->server.len);
|
|
||||||
if (dst->server.data == NULL) {
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_memcpy(dst->server.data, src->server.data, src->server.len);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dst;
|
|
||||||
|
|
||||||
failed:
|
|
||||||
|
|
||||||
if (dst->server.data) {
|
|
||||||
ngx_slab_free_locked(pool, dst->server.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dst->name.data) {
|
|
||||||
ngx_slab_free_locked(pool, dst->name.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dst->sockaddr) {
|
|
||||||
ngx_slab_free_locked(pool, dst->sockaddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_slab_free_locked(pool, dst);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -382,13 +382,6 @@ ngx_http_init_phases(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ngx_array_init(&cmcf->phases[NGX_HTTP_PRECONTENT_PHASE].handlers,
|
|
||||||
cf->pool, 2, sizeof(ngx_http_handler_pt))
|
|
||||||
!= NGX_OK)
|
|
||||||
{
|
|
||||||
return NGX_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers,
|
if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers,
|
||||||
cf->pool, 4, sizeof(ngx_http_handler_pt))
|
cf->pool, 4, sizeof(ngx_http_handler_pt))
|
||||||
!= NGX_OK)
|
!= NGX_OK)
|
||||||
@@ -466,7 +459,8 @@ ngx_http_init_phase_handlers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf)
|
|||||||
|
|
||||||
n = 1 /* find config phase */
|
n = 1 /* find config phase */
|
||||||
+ use_rewrite /* post rewrite phase */
|
+ use_rewrite /* post rewrite phase */
|
||||||
+ use_access; /* post access phase */
|
+ use_access /* post access phase */
|
||||||
|
+ cmcf->try_files;
|
||||||
|
|
||||||
for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) {
|
for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) {
|
||||||
n += cmcf->phases[i].handlers.nelts;
|
n += cmcf->phases[i].handlers.nelts;
|
||||||
@@ -535,6 +529,15 @@ ngx_http_init_phase_handlers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf)
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
case NGX_HTTP_TRY_FILES_PHASE:
|
||||||
|
if (cmcf->try_files) {
|
||||||
|
ph->checker = ngx_http_core_try_files_phase;
|
||||||
|
n++;
|
||||||
|
ph++;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
|
||||||
case NGX_HTTP_CONTENT_PHASE:
|
case NGX_HTTP_CONTENT_PHASE:
|
||||||
checker = ngx_http_core_content_phase;
|
checker = ngx_http_core_content_phase;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||||||
void *conf);
|
void *conf);
|
||||||
static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf);
|
void *conf);
|
||||||
|
static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
|
void *conf);
|
||||||
static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf);
|
void *conf);
|
||||||
static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
@@ -647,6 +649,13 @@ static ngx_command_t ngx_http_core_commands[] = {
|
|||||||
0,
|
0,
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
|
{ ngx_string("try_files"),
|
||||||
|
NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
|
||||||
|
ngx_http_core_try_files,
|
||||||
|
NGX_HTTP_LOC_CONF_OFFSET,
|
||||||
|
0,
|
||||||
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("post_action"),
|
{ ngx_string("post_action"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
||||||
|NGX_CONF_TAKE1,
|
|NGX_CONF_TAKE1,
|
||||||
@@ -1149,6 +1158,223 @@ ngx_http_core_post_access_phase(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ngx_int_t
|
||||||
|
ngx_http_core_try_files_phase(ngx_http_request_t *r,
|
||||||
|
ngx_http_phase_handler_t *ph)
|
||||||
|
{
|
||||||
|
size_t len, root, alias, reserve, allocated;
|
||||||
|
u_char *p, *name;
|
||||||
|
ngx_str_t path, args;
|
||||||
|
ngx_uint_t test_dir;
|
||||||
|
ngx_http_try_file_t *tf;
|
||||||
|
ngx_open_file_info_t of;
|
||||||
|
ngx_http_script_code_pt code;
|
||||||
|
ngx_http_script_engine_t e;
|
||||||
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
|
ngx_http_script_len_code_pt lcode;
|
||||||
|
|
||||||
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||||
|
"try files phase: %ui", r->phase_handler);
|
||||||
|
|
||||||
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
|
|
||||||
|
if (clcf->try_files == NULL) {
|
||||||
|
r->phase_handler++;
|
||||||
|
return NGX_AGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
allocated = 0;
|
||||||
|
root = 0;
|
||||||
|
name = NULL;
|
||||||
|
/* suppress MSVC warning */
|
||||||
|
path.data = NULL;
|
||||||
|
|
||||||
|
tf = clcf->try_files;
|
||||||
|
|
||||||
|
alias = clcf->alias;
|
||||||
|
|
||||||
|
for ( ;; ) {
|
||||||
|
|
||||||
|
if (tf->lengths) {
|
||||||
|
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
||||||
|
|
||||||
|
e.ip = tf->lengths->elts;
|
||||||
|
e.request = r;
|
||||||
|
|
||||||
|
/* 1 is for terminating '\0' as in static names */
|
||||||
|
len = 1;
|
||||||
|
|
||||||
|
while (*(uintptr_t *) e.ip) {
|
||||||
|
lcode = *(ngx_http_script_len_code_pt *) e.ip;
|
||||||
|
len += lcode(&e);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
len = tf->name.len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!alias) {
|
||||||
|
reserve = len > r->uri.len ? len - r->uri.len : 0;
|
||||||
|
|
||||||
|
} else if (alias == NGX_MAX_SIZE_T_VALUE) {
|
||||||
|
reserve = len;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
reserve = len > r->uri.len - alias ? len - (r->uri.len - alias) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reserve > allocated || !allocated) {
|
||||||
|
|
||||||
|
/* 16 bytes are preallocation */
|
||||||
|
allocated = reserve + 16;
|
||||||
|
|
||||||
|
if (ngx_http_map_uri_to_path(r, &path, &root, allocated) == NULL) {
|
||||||
|
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
name = path.data + root;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tf->values == NULL) {
|
||||||
|
|
||||||
|
/* tf->name.len includes the terminating '\0' */
|
||||||
|
|
||||||
|
ngx_memcpy(name, tf->name.data, tf->name.len);
|
||||||
|
|
||||||
|
path.len = (name + tf->name.len - 1) - path.data;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
e.ip = tf->values->elts;
|
||||||
|
e.pos = name;
|
||||||
|
e.flushed = 1;
|
||||||
|
|
||||||
|
while (*(uintptr_t *) e.ip) {
|
||||||
|
code = *(ngx_http_script_code_pt *) e.ip;
|
||||||
|
code((ngx_http_script_engine_t *) &e);
|
||||||
|
}
|
||||||
|
|
||||||
|
path.len = e.pos - path.data;
|
||||||
|
|
||||||
|
*e.pos = '\0';
|
||||||
|
|
||||||
|
if (alias && alias != NGX_MAX_SIZE_T_VALUE
|
||||||
|
&& ngx_strncmp(name, r->uri.data, alias) == 0)
|
||||||
|
{
|
||||||
|
ngx_memmove(name, name + alias, len - alias);
|
||||||
|
path.len -= alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test_dir = tf->test_dir;
|
||||||
|
|
||||||
|
tf++;
|
||||||
|
|
||||||
|
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||||
|
"trying to use %s: \"%s\" \"%s\"",
|
||||||
|
test_dir ? "dir" : "file", name, path.data);
|
||||||
|
|
||||||
|
if (tf->lengths == NULL && tf->name.len == 0) {
|
||||||
|
|
||||||
|
if (tf->code) {
|
||||||
|
ngx_http_finalize_request(r, tf->code);
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
path.len -= root;
|
||||||
|
path.data += root;
|
||||||
|
|
||||||
|
if (path.data[0] == '@') {
|
||||||
|
(void) ngx_http_named_location(r, &path);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ngx_http_split_args(r, &path, &args);
|
||||||
|
|
||||||
|
(void) ngx_http_internal_redirect(r, &path, &args);
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_http_finalize_request(r, NGX_DONE);
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_memzero(&of, sizeof(ngx_open_file_info_t));
|
||||||
|
|
||||||
|
of.read_ahead = clcf->read_ahead;
|
||||||
|
of.directio = clcf->directio;
|
||||||
|
of.valid = clcf->open_file_cache_valid;
|
||||||
|
of.min_uses = clcf->open_file_cache_min_uses;
|
||||||
|
of.test_only = 1;
|
||||||
|
of.errors = clcf->open_file_cache_errors;
|
||||||
|
of.events = clcf->open_file_cache_events;
|
||||||
|
|
||||||
|
if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) {
|
||||||
|
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
|
||||||
|
!= NGX_OK)
|
||||||
|
{
|
||||||
|
if (of.err == 0) {
|
||||||
|
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (of.err != NGX_ENOENT
|
||||||
|
&& of.err != NGX_ENOTDIR
|
||||||
|
&& of.err != NGX_ENAMETOOLONG)
|
||||||
|
{
|
||||||
|
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
|
||||||
|
"%s \"%s\" failed", of.failed, path.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (of.is_dir != test_dir) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
path.len -= root;
|
||||||
|
path.data += root;
|
||||||
|
|
||||||
|
if (!alias) {
|
||||||
|
r->uri = path;
|
||||||
|
|
||||||
|
} else if (alias == NGX_MAX_SIZE_T_VALUE) {
|
||||||
|
if (!test_dir) {
|
||||||
|
r->uri = path;
|
||||||
|
r->add_uri_to_alias = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
name = r->uri.data;
|
||||||
|
|
||||||
|
r->uri.len = alias + path.len;
|
||||||
|
r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
|
||||||
|
if (r->uri.data == NULL) {
|
||||||
|
r->uri.len = 0;
|
||||||
|
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = ngx_copy(r->uri.data, name, alias);
|
||||||
|
ngx_memcpy(p, path.data, path.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_http_set_exten(r);
|
||||||
|
|
||||||
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||||
|
"try file uri: \"%V\"", &r->uri);
|
||||||
|
|
||||||
|
r->phase_handler++;
|
||||||
|
return NGX_AGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* not reached */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ngx_int_t
|
ngx_int_t
|
||||||
ngx_http_core_content_phase(ngx_http_request_t *r,
|
ngx_http_core_content_phase(ngx_http_request_t *r,
|
||||||
ngx_http_phase_handler_t *ph)
|
ngx_http_phase_handler_t *ph)
|
||||||
@@ -3335,6 +3561,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
|||||||
* clcf->default_type = { 0, NULL };
|
* clcf->default_type = { 0, NULL };
|
||||||
* clcf->error_log = NULL;
|
* clcf->error_log = NULL;
|
||||||
* clcf->error_pages = NULL;
|
* clcf->error_pages = NULL;
|
||||||
|
* clcf->try_files = NULL;
|
||||||
* clcf->client_body_path = NULL;
|
* clcf->client_body_path = NULL;
|
||||||
* clcf->regex = NULL;
|
* clcf->regex = NULL;
|
||||||
* clcf->exact_match = 0;
|
* clcf->exact_match = 0;
|
||||||
@@ -4657,6 +4884,89 @@ ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *
|
||||||
|
ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
|
{
|
||||||
|
ngx_http_core_loc_conf_t *clcf = conf;
|
||||||
|
|
||||||
|
ngx_str_t *value;
|
||||||
|
ngx_int_t code;
|
||||||
|
ngx_uint_t i, n;
|
||||||
|
ngx_http_try_file_t *tf;
|
||||||
|
ngx_http_script_compile_t sc;
|
||||||
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
|
|
||||||
|
if (clcf->try_files) {
|
||||||
|
return "is duplicate";
|
||||||
|
}
|
||||||
|
|
||||||
|
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
||||||
|
|
||||||
|
cmcf->try_files = 1;
|
||||||
|
|
||||||
|
tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
|
||||||
|
if (tf == NULL) {
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
clcf->try_files = tf;
|
||||||
|
|
||||||
|
value = cf->args->elts;
|
||||||
|
|
||||||
|
for (i = 0; i < cf->args->nelts - 1; i++) {
|
||||||
|
|
||||||
|
tf[i].name = value[i + 1];
|
||||||
|
|
||||||
|
if (tf[i].name.len > 0
|
||||||
|
&& tf[i].name.data[tf[i].name.len - 1] == '/'
|
||||||
|
&& i + 2 < cf->args->nelts)
|
||||||
|
{
|
||||||
|
tf[i].test_dir = 1;
|
||||||
|
tf[i].name.len--;
|
||||||
|
tf[i].name.data[tf[i].name.len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ngx_http_script_variables_count(&tf[i].name);
|
||||||
|
|
||||||
|
if (n) {
|
||||||
|
ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
||||||
|
|
||||||
|
sc.cf = cf;
|
||||||
|
sc.source = &tf[i].name;
|
||||||
|
sc.lengths = &tf[i].lengths;
|
||||||
|
sc.values = &tf[i].values;
|
||||||
|
sc.variables = n;
|
||||||
|
sc.complete_lengths = 1;
|
||||||
|
sc.complete_values = 1;
|
||||||
|
|
||||||
|
if (ngx_http_script_compile(&sc) != NGX_OK) {
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* add trailing '\0' to length */
|
||||||
|
tf[i].name.len++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tf[i - 1].name.data[0] == '=') {
|
||||||
|
|
||||||
|
code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2);
|
||||||
|
|
||||||
|
if (code == NGX_ERROR || code > 999) {
|
||||||
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
|
"invalid code \"%*s\"",
|
||||||
|
tf[i - 1].name.len - 1, tf[i - 1].name.data);
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
tf[i].code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NGX_CONF_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -119,8 +119,7 @@ typedef enum {
|
|||||||
NGX_HTTP_ACCESS_PHASE,
|
NGX_HTTP_ACCESS_PHASE,
|
||||||
NGX_HTTP_POST_ACCESS_PHASE,
|
NGX_HTTP_POST_ACCESS_PHASE,
|
||||||
|
|
||||||
NGX_HTTP_PRECONTENT_PHASE,
|
NGX_HTTP_TRY_FILES_PHASE,
|
||||||
|
|
||||||
NGX_HTTP_CONTENT_PHASE,
|
NGX_HTTP_CONTENT_PHASE,
|
||||||
|
|
||||||
NGX_HTTP_LOG_PHASE
|
NGX_HTTP_LOG_PHASE
|
||||||
@@ -173,6 +172,8 @@ typedef struct {
|
|||||||
|
|
||||||
ngx_array_t *ports;
|
ngx_array_t *ports;
|
||||||
|
|
||||||
|
ngx_uint_t try_files; /* unsigned try_files:1 */
|
||||||
|
|
||||||
ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
|
ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
|
||||||
} ngx_http_core_main_conf_t;
|
} ngx_http_core_main_conf_t;
|
||||||
|
|
||||||
@@ -295,6 +296,16 @@ typedef struct {
|
|||||||
} ngx_http_err_page_t;
|
} ngx_http_err_page_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ngx_array_t *lengths;
|
||||||
|
ngx_array_t *values;
|
||||||
|
ngx_str_t name;
|
||||||
|
|
||||||
|
unsigned code:10;
|
||||||
|
unsigned test_dir:1;
|
||||||
|
} ngx_http_try_file_t;
|
||||||
|
|
||||||
|
|
||||||
struct ngx_http_core_loc_conf_s {
|
struct ngx_http_core_loc_conf_s {
|
||||||
ngx_str_t name; /* location name */
|
ngx_str_t name; /* location name */
|
||||||
|
|
||||||
@@ -414,6 +425,7 @@ struct ngx_http_core_loc_conf_s {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ngx_array_t *error_pages; /* error_page */
|
ngx_array_t *error_pages; /* error_page */
|
||||||
|
ngx_http_try_file_t *try_files; /* try_files */
|
||||||
|
|
||||||
ngx_path_t *client_body_temp_path; /* client_body_temp_path */
|
ngx_path_t *client_body_temp_path; /* client_body_temp_path */
|
||||||
|
|
||||||
@@ -474,6 +486,8 @@ ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
|
|||||||
ngx_http_phase_handler_t *ph);
|
ngx_http_phase_handler_t *ph);
|
||||||
ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
|
ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
|
||||||
ngx_http_phase_handler_t *ph);
|
ngx_http_phase_handler_t *ph);
|
||||||
|
ngx_int_t ngx_http_core_try_files_phase(ngx_http_request_t *r,
|
||||||
|
ngx_http_phase_handler_t *ph);
|
||||||
ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
|
ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
|
||||||
ngx_http_phase_handler_t *ph);
|
ngx_http_phase_handler_t *ph);
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,6 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
|
|||||||
if (shm_zone->shm.exists) {
|
if (shm_zone->shm.exists) {
|
||||||
cache->sh = cache->shpool->data;
|
cache->sh = cache->shpool->data;
|
||||||
cache->bsize = ngx_fs_bsize(cache->path->name.data);
|
cache->bsize = ngx_fs_bsize(cache->path->name.data);
|
||||||
cache->max_size /= cache->bsize;
|
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -742,7 +742,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
|
|||||||
return NGX_HTTP_PARSE_INVALID_REQUEST;
|
return NGX_HTTP_PARSE_INVALID_REQUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->http_major = r->http_major * 10 + (ch - '0');
|
r->http_major = r->http_major * 10 + ch - '0';
|
||||||
|
|
||||||
if (r->http_major > 1) {
|
if (r->http_major > 1) {
|
||||||
return NGX_HTTP_PARSE_INVALID_VERSION;
|
return NGX_HTTP_PARSE_INVALID_VERSION;
|
||||||
@@ -784,7 +784,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
|
|||||||
return NGX_HTTP_PARSE_INVALID_REQUEST;
|
return NGX_HTTP_PARSE_INVALID_REQUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->http_minor = r->http_minor * 10 + (ch - '0');
|
r->http_minor = r->http_minor * 10 + ch - '0';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sw_spaces_after_digit:
|
case sw_spaces_after_digit:
|
||||||
@@ -1518,7 +1518,7 @@ ngx_http_parse_complex_uri(ngx_http_request_t *r, ngx_uint_t merge_slashes)
|
|||||||
|
|
||||||
case sw_quoted_second:
|
case sw_quoted_second:
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
ch = (u_char) ((decoded << 4) + (ch - '0'));
|
ch = (u_char) ((decoded << 4) + ch - '0');
|
||||||
|
|
||||||
if (ch == '%' || ch == '#') {
|
if (ch == '%' || ch == '#') {
|
||||||
state = sw_usual;
|
state = sw_usual;
|
||||||
@@ -1536,7 +1536,7 @@ ngx_http_parse_complex_uri(ngx_http_request_t *r, ngx_uint_t merge_slashes)
|
|||||||
|
|
||||||
c = (u_char) (ch | 0x20);
|
c = (u_char) (ch | 0x20);
|
||||||
if (c >= 'a' && c <= 'f') {
|
if (c >= 'a' && c <= 'f') {
|
||||||
ch = (u_char) ((decoded << 4) + (c - 'a') + 10);
|
ch = (u_char) ((decoded << 4) + c - 'a' + 10);
|
||||||
|
|
||||||
if (ch == '?') {
|
if (ch == '?') {
|
||||||
state = sw_usual;
|
state = sw_usual;
|
||||||
@@ -1701,7 +1701,7 @@ ngx_http_parse_status_line(ngx_http_request_t *r, ngx_buf_t *b,
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->http_major = r->http_major * 10 + (ch - '0');
|
r->http_major = r->http_major * 10 + ch - '0';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* the first digit of minor HTTP version */
|
/* the first digit of minor HTTP version */
|
||||||
@@ -1729,7 +1729,7 @@ ngx_http_parse_status_line(ngx_http_request_t *r, ngx_buf_t *b,
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->http_minor = r->http_minor * 10 + (ch - '0');
|
r->http_minor = r->http_minor * 10 + ch - '0';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* HTTP status code */
|
/* HTTP status code */
|
||||||
@@ -1742,7 +1742,7 @@ ngx_http_parse_status_line(ngx_http_request_t *r, ngx_buf_t *b,
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status->code = status->code * 10 + (ch - '0');
|
status->code = status->code * 10 + ch - '0';
|
||||||
|
|
||||||
if (++status->count == 3) {
|
if (++status->count == 3) {
|
||||||
state = sw_space_after_status;
|
state = sw_space_after_status;
|
||||||
|
|||||||
@@ -537,7 +537,6 @@ struct ngx_http_request_s {
|
|||||||
unsigned main_filter_need_in_memory:1;
|
unsigned main_filter_need_in_memory:1;
|
||||||
unsigned filter_need_in_memory:1;
|
unsigned filter_need_in_memory:1;
|
||||||
unsigned filter_need_temporary:1;
|
unsigned filter_need_temporary:1;
|
||||||
unsigned preserve_body:1;
|
|
||||||
unsigned allow_ranges:1;
|
unsigned allow_ranges:1;
|
||||||
unsigned subrequest_ranges:1;
|
unsigned subrequest_ranges:1;
|
||||||
unsigned single_range:1;
|
unsigned single_range:1;
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ static ngx_http_variable_t ngx_http_upstream_vars[] = {
|
|||||||
{ ngx_string("upstream_cookie_"), NULL, ngx_http_upstream_cookie_variable,
|
{ ngx_string("upstream_cookie_"), NULL, ngx_http_upstream_cookie_variable,
|
||||||
0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
|
0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1077,10 +1077,6 @@ ngx_http_upstream_cache_background_update(ngx_http_request_t *r,
|
|||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r == r->main) {
|
|
||||||
r->preserve_body = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL,
|
if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL,
|
||||||
NGX_HTTP_SUBREQUEST_CLONE
|
NGX_HTTP_SUBREQUEST_CLONE
|
||||||
|NGX_HTTP_SUBREQUEST_BACKGROUND)
|
|NGX_HTTP_SUBREQUEST_BACKGROUND)
|
||||||
@@ -2861,9 +2857,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
|||||||
u->pipe->downstream_error = 1;
|
u->pipe->downstream_error = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r->request_body && r->request_body->temp_file
|
if (r->request_body && r->request_body->temp_file) {
|
||||||
&& r == r->main && !r->preserve_body)
|
|
||||||
{
|
|
||||||
ngx_pool_run_cleanup_file(r->pool, r->request_body->temp_file->file.fd);
|
ngx_pool_run_cleanup_file(r->pool, r->request_body->temp_file->file.fd);
|
||||||
r->request_body->temp_file->file.fd = NGX_INVALID_FILE;
|
r->request_body->temp_file->file.fd = NGX_INVALID_FILE;
|
||||||
}
|
}
|
||||||
@@ -4509,7 +4503,7 @@ ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*p >= '0' && *p <= '9') {
|
if (*p >= '0' && *p <= '9') {
|
||||||
n = n * 10 + (*p - '0');
|
n = n * 10 + *p - '0';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4537,7 +4531,7 @@ ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*p >= '0' && *p <= '9') {
|
if (*p >= '0' && *p <= '9') {
|
||||||
n = n * 10 + (*p - '0');
|
n = n * 10 + *p - '0';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4560,7 +4554,7 @@ ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*p >= '0' && *p <= '9') {
|
if (*p >= '0' && *p <= '9') {
|
||||||
n = n * 10 + (*p - '0');
|
n = n * 10 + *p - '0';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
|
|||||||
{ ngx_string("arg_"), NULL, ngx_http_variable_argument,
|
{ ngx_string("arg_"), NULL, ngx_http_variable_argument,
|
||||||
0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
|
0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ struct ngx_http_variable_s {
|
|||||||
ngx_uint_t index;
|
ngx_uint_t index;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ngx_http_null_variable { ngx_null_string, NULL, NULL, 0, 0, 0 }
|
|
||||||
|
|
||||||
|
|
||||||
ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name,
|
ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name,
|
||||||
ngx_uint_t flags);
|
ngx_uint_t flags);
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ static ngx_http_variable_t ngx_http_v2_vars[] = {
|
|||||||
{ ngx_string("http2"), NULL,
|
{ ngx_string("http2"), NULL,
|
||||||
ngx_http_v2_variable, 0, 0, 0 },
|
ngx_http_v2_variable, 0, 0, 0 },
|
||||||
|
|
||||||
ngx_http_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ static ngx_stream_variable_t ngx_stream_geoip_vars[] = {
|
|||||||
ngx_stream_geoip_city_int_variable,
|
ngx_stream_geoip_city_int_variable,
|
||||||
offsetof(GeoIPRecord, area_code), 0, 0 },
|
offsetof(GeoIPRecord, area_code), 0, 0 },
|
||||||
|
|
||||||
ngx_stream_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ static ngx_stream_variable_t ngx_stream_realip_vars[] = {
|
|||||||
{ ngx_string("realip_remote_port"), NULL,
|
{ ngx_string("realip_remote_port"), NULL,
|
||||||
ngx_stream_realip_remote_port_variable, 0, 0, 0 },
|
ngx_stream_realip_remote_port_variable, 0, 0, 0 },
|
||||||
|
|
||||||
ngx_stream_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ static ngx_stream_variable_t ngx_stream_ssl_vars[] = {
|
|||||||
{ ngx_string("ssl_client_v_remain"), NULL, ngx_stream_ssl_variable,
|
{ ngx_string("ssl_client_v_remain"), NULL, ngx_stream_ssl_variable,
|
||||||
(uintptr_t) ngx_ssl_get_client_v_remain, NGX_STREAM_VAR_CHANGEABLE, 0 },
|
(uintptr_t) ngx_ssl_get_client_v_remain, NGX_STREAM_VAR_CHANGEABLE, 0 },
|
||||||
|
|
||||||
ngx_stream_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ static ngx_stream_variable_t ngx_stream_ssl_preread_vars[] = {
|
|||||||
{ ngx_string("ssl_preread_server_name"), NULL,
|
{ ngx_string("ssl_preread_server_name"), NULL,
|
||||||
ngx_stream_ssl_preread_server_name_variable, 0, 0, 0 },
|
ngx_stream_ssl_preread_server_name_variable, 0, 0, 0 },
|
||||||
|
|
||||||
ngx_stream_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ static ngx_stream_variable_t ngx_stream_upstream_vars[] = {
|
|||||||
ngx_stream_upstream_bytes_variable, 1,
|
ngx_stream_upstream_bytes_variable, 1,
|
||||||
NGX_STREAM_VAR_NOCACHEABLE, 0 },
|
NGX_STREAM_VAR_NOCACHEABLE, 0 },
|
||||||
|
|
||||||
ngx_stream_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ static ngx_int_t ngx_stream_upstream_init_zone(ngx_shm_zone_t *shm_zone,
|
|||||||
void *data);
|
void *data);
|
||||||
static ngx_stream_upstream_rr_peers_t *ngx_stream_upstream_zone_copy_peers(
|
static ngx_stream_upstream_rr_peers_t *ngx_stream_upstream_zone_copy_peers(
|
||||||
ngx_slab_pool_t *shpool, ngx_stream_upstream_srv_conf_t *uscf);
|
ngx_slab_pool_t *shpool, ngx_stream_upstream_srv_conf_t *uscf);
|
||||||
static ngx_stream_upstream_rr_peer_t *ngx_stream_upstream_zone_copy_peer(
|
|
||||||
ngx_stream_upstream_rr_peers_t *peers, ngx_stream_upstream_rr_peer_t *src);
|
|
||||||
|
|
||||||
|
|
||||||
static ngx_command_t ngx_stream_upstream_zone_commands[] = {
|
static ngx_command_t ngx_stream_upstream_zone_commands[] = {
|
||||||
@@ -184,7 +182,6 @@ static ngx_stream_upstream_rr_peers_t *
|
|||||||
ngx_stream_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
ngx_stream_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
||||||
ngx_stream_upstream_srv_conf_t *uscf)
|
ngx_stream_upstream_srv_conf_t *uscf)
|
||||||
{
|
{
|
||||||
ngx_str_t *name;
|
|
||||||
ngx_stream_upstream_rr_peer_t *peer, **peerp;
|
ngx_stream_upstream_rr_peer_t *peer, **peerp;
|
||||||
ngx_stream_upstream_rr_peers_t *peers, *backup;
|
ngx_stream_upstream_rr_peers_t *peers, *backup;
|
||||||
|
|
||||||
@@ -195,30 +192,18 @@ ngx_stream_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
|||||||
|
|
||||||
ngx_memcpy(peers, uscf->peer.data, sizeof(ngx_stream_upstream_rr_peers_t));
|
ngx_memcpy(peers, uscf->peer.data, sizeof(ngx_stream_upstream_rr_peers_t));
|
||||||
|
|
||||||
name = ngx_slab_alloc(shpool, sizeof(ngx_str_t));
|
|
||||||
if (name == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
name->data = ngx_slab_alloc(shpool, peers->name->len);
|
|
||||||
if (name->data == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_memcpy(name->data, peers->name->data, peers->name->len);
|
|
||||||
name->len = peers->name->len;
|
|
||||||
|
|
||||||
peers->name = name;
|
|
||||||
|
|
||||||
peers->shpool = shpool;
|
peers->shpool = shpool;
|
||||||
|
|
||||||
for (peerp = &peers->peer; *peerp; peerp = &peer->next) {
|
for (peerp = &peers->peer; *peerp; peerp = &peer->next) {
|
||||||
/* pool is unlocked */
|
/* pool is unlocked */
|
||||||
peer = ngx_stream_upstream_zone_copy_peer(peers, *peerp);
|
peer = ngx_slab_calloc_locked(shpool,
|
||||||
|
sizeof(ngx_stream_upstream_rr_peer_t));
|
||||||
if (peer == NULL) {
|
if (peer == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngx_memcpy(peer, *peerp, sizeof(ngx_stream_upstream_rr_peer_t));
|
||||||
|
|
||||||
*peerp = peer;
|
*peerp = peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,17 +218,18 @@ ngx_stream_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
|||||||
|
|
||||||
ngx_memcpy(backup, peers->next, sizeof(ngx_stream_upstream_rr_peers_t));
|
ngx_memcpy(backup, peers->next, sizeof(ngx_stream_upstream_rr_peers_t));
|
||||||
|
|
||||||
backup->name = name;
|
|
||||||
|
|
||||||
backup->shpool = shpool;
|
backup->shpool = shpool;
|
||||||
|
|
||||||
for (peerp = &backup->peer; *peerp; peerp = &peer->next) {
|
for (peerp = &backup->peer; *peerp; peerp = &peer->next) {
|
||||||
/* pool is unlocked */
|
/* pool is unlocked */
|
||||||
peer = ngx_stream_upstream_zone_copy_peer(backup, *peerp);
|
peer = ngx_slab_calloc_locked(shpool,
|
||||||
|
sizeof(ngx_stream_upstream_rr_peer_t));
|
||||||
if (peer == NULL) {
|
if (peer == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngx_memcpy(peer, *peerp, sizeof(ngx_stream_upstream_rr_peer_t));
|
||||||
|
|
||||||
*peerp = peer;
|
*peerp = peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,68 +241,3 @@ done:
|
|||||||
|
|
||||||
return peers;
|
return peers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ngx_stream_upstream_rr_peer_t *
|
|
||||||
ngx_stream_upstream_zone_copy_peer(ngx_stream_upstream_rr_peers_t *peers,
|
|
||||||
ngx_stream_upstream_rr_peer_t *src)
|
|
||||||
{
|
|
||||||
ngx_slab_pool_t *pool;
|
|
||||||
ngx_stream_upstream_rr_peer_t *dst;
|
|
||||||
|
|
||||||
pool = peers->shpool;
|
|
||||||
|
|
||||||
dst = ngx_slab_calloc_locked(pool, sizeof(ngx_stream_upstream_rr_peer_t));
|
|
||||||
if (dst == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src) {
|
|
||||||
ngx_memcpy(dst, src, sizeof(ngx_stream_upstream_rr_peer_t));
|
|
||||||
dst->sockaddr = NULL;
|
|
||||||
dst->name.data = NULL;
|
|
||||||
dst->server.data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst->sockaddr = ngx_slab_calloc_locked(pool, NGX_SOCKADDRLEN);
|
|
||||||
if (dst->sockaddr == NULL) {
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst->name.data = ngx_slab_calloc_locked(pool, NGX_SOCKADDR_STRLEN);
|
|
||||||
if (dst->name.data == NULL) {
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src) {
|
|
||||||
ngx_memcpy(dst->sockaddr, src->sockaddr, src->socklen);
|
|
||||||
ngx_memcpy(dst->name.data, src->name.data, src->name.len);
|
|
||||||
|
|
||||||
dst->server.data = ngx_slab_alloc_locked(pool, src->server.len);
|
|
||||||
if (dst->server.data == NULL) {
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_memcpy(dst->server.data, src->server.data, src->server.len);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dst;
|
|
||||||
|
|
||||||
failed:
|
|
||||||
|
|
||||||
if (dst->server.data) {
|
|
||||||
ngx_slab_free_locked(pool, dst->server.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dst->name.data) {
|
|
||||||
ngx_slab_free_locked(pool, dst->name.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dst->sockaddr) {
|
|
||||||
ngx_slab_free_locked(pool, dst->sockaddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_slab_free_locked(pool, dst);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ static ngx_stream_variable_t ngx_stream_core_variables[] = {
|
|||||||
{ ngx_string("protocol"), NULL,
|
{ ngx_string("protocol"), NULL,
|
||||||
ngx_stream_variable_protocol, 0, 0, 0 },
|
ngx_stream_variable_protocol, 0, 0, 0 },
|
||||||
|
|
||||||
ngx_stream_null_variable
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ struct ngx_stream_variable_s {
|
|||||||
ngx_uint_t index;
|
ngx_uint_t index;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ngx_stream_null_variable { ngx_null_string, NULL, NULL, 0, 0, 0 }
|
|
||||||
|
|
||||||
|
|
||||||
ngx_stream_variable_t *ngx_stream_add_variable(ngx_conf_t *cf, ngx_str_t *name,
|
ngx_stream_variable_t *ngx_stream_add_variable(ngx_conf_t *cf, ngx_str_t *name,
|
||||||
ngx_uint_t flags);
|
ngx_uint_t flags);
|
||||||
|
|||||||
Reference in New Issue
Block a user