summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto/cc/conf4
-rw-r--r--auto/cc/gcc15
-rw-r--r--auto/cc/icc2
-rw-r--r--auto/cc/owc2
-rw-r--r--auto/modules6
-rw-r--r--auto/options6
-rw-r--r--docs/xml/nginx/changes.xml101
-rw-r--r--src/core/nginx.h2
-rw-r--r--src/core/ngx_conf_file.c22
-rw-r--r--src/core/ngx_connection.c1
-rw-r--r--src/core/ngx_inet.c2
-rw-r--r--src/core/ngx_radix_tree.c49
-rw-r--r--src/core/ngx_radix_tree.h7
-rw-r--r--src/event/modules/ngx_devpoll_module.c4
-rw-r--r--src/event/modules/ngx_select_module.c9
-rw-r--r--src/event/ngx_event_accept.c2
-rw-r--r--src/event/ngx_event_connect.c47
-rw-r--r--src/event/ngx_event_connect.h18
-rw-r--r--src/http/modules/ngx_http_fastcgi_handler.c205
-rw-r--r--src/http/modules/ngx_http_geo_module.c2
-rw-r--r--src/http/modules/ngx_http_rewrite_handler.c106
-rw-r--r--src/http/modules/ngx_http_stub_status_module.c138
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c14
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.h2
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_upstream.c55
-rw-r--r--src/http/ngx_http_core_module.c348
-rw-r--r--src/http/ngx_http_log_handler.c5
-rw-r--r--src/http/ngx_http_special_response.c3
-rw-r--r--src/http/ngx_http_upstream.c117
-rw-r--r--src/http/ngx_http_upstream.h8
30 files changed, 898 insertions, 404 deletions
diff --git a/auto/cc/conf b/auto/cc/conf
index 0a5db9e34..f064bca0d 100644
--- a/auto/cc/conf
+++ b/auto/cc/conf
@@ -2,6 +2,8 @@
# Copyright (C) Igor Sysoev
+LINK="\$(CC)"
+
ngx_include_opt="-I "
ngx_compile_opt="-c"
ngx_objout="-o "
@@ -56,7 +58,7 @@ else
# # Compaq C V6.5-207
#
# . auto/cc/ccc
- ngx_include_opt="-I "
+ ngx_include_opt="-I"
;;
# acc)
diff --git a/auto/cc/gcc b/auto/cc/gcc
index 24b908d26..d6647e52f 100644
--- a/auto/cc/gcc
+++ b/auto/cc/gcc
@@ -27,8 +27,13 @@ fi
# optimizations
-#CFLAGS="$CFLAGS -O2 -fomit-frame-pointer"
-#CFLAGS="$CFLAGS -Os -fomit-frame-pointer"
+#NGX_GCC_OPT="-O2"
+#NGX_GCC_OPT="-Os"
+NGX_GCC_OPT="-O"
+
+CFLAGS="$CFLAGS $NGX_GCC_OPT"
+
+#CFLAGS="$CFLAGS -fomit-frame-pointer"
case $CPU in
pentium)
@@ -83,7 +88,9 @@ fi
# warnings
-CFLAGS="$CFLAGS -O -W"
+# -W requires at least -O
+CFLAGS="$CFLAGS ${NGX_GCC_OPT:-O} -W"
+
CFLAGS="$CFLAGS -Wall -Wpointer-arith"
#CFLAGS="$CFLAGS -Wconversion"
#CFLAGS="$CFLAGS -Winline"
@@ -103,5 +110,3 @@ CFLAGS="$CFLAGS -g"
if [ ".$CPP" = "." ]; then
CPP="$CC -E"
fi
-
-LINK="\$(CC)"
diff --git a/auto/cc/icc b/auto/cc/icc
index b036cb645..2195c10db 100644
--- a/auto/cc/icc
+++ b/auto/cc/icc
@@ -68,5 +68,3 @@ CFLAGS="$CFLAGS -Werror"
# debug
CFLAGS="$CFLAGS -g"
-
-LINK="\$(CC)"
diff --git a/auto/cc/owc b/auto/cc/owc
index 88ffdb1f8..06e5cc0e0 100644
--- a/auto/cc/owc
+++ b/auto/cc/owc
@@ -69,8 +69,6 @@ NGX_BUILD_PCH="-fhq=$NGX_OBJS/ngx_config.pch"
NGX_USE_PCH="-fh=$NGX_OBJS/ngx_config.pch"
-LINK="\$(CC)"
-
# the link flags, built target is NT GUI mode application
CORE_LINK="$CORE_LINK -l=nt_win"
diff --git a/auto/modules b/auto/modules
index 375b755f0..2c001e28b 100644
--- a/auto/modules
+++ b/auto/modules
@@ -156,6 +156,12 @@ fi
#HTTP_SRCS="$HTTP_SRCS $HTPP_CACHE_SRCS"
#HTTP_SRCS="$HTTP_SRCS $HTPP_FILE_CACHE_SRCS"
+if [ $HTTP_STUB_STATUS = YES ]; then
+ have=NGX_STAT_STUB . auto/have
+ HTTP_MODULES="$HTTP_MODULES ngx_http_stub_status_module"
+ HTTP_SRCS="$HTTP_SRCS src/http/modules/ngx_http_stub_status_module.c"
+fi
+
if [ -r $NGX_OBJS/auto ]; then
. $NGX_OBJS/auto
fi
diff --git a/auto/options b/auto/options
index 9aff6e228..7bb93ac74 100644
--- a/auto/options
+++ b/auto/options
@@ -58,6 +58,9 @@ HTTP_REWRITE=YES
HTTP_PROXY=YES
HTTP_FASTCGI=YES
+# STUB
+HTTP_STUB_STATUS=NO
+
IMAP=NO
NGX_MODULES=
@@ -131,6 +134,9 @@ do
--without-http_proxy_module) HTTP_PROXY=NO ;;
--without-http_fastcgi_module) HTTP_FASTCGI=NO ;;
+ # STUB
+ --with-http_stub_status_module) HTTP_STUB_STATUS=YES ;;
+
--with-imap) IMAP=YES ;;
--with-module=*) NGX_MODULES="$NGX_MODULES $values" ;;
diff --git a/docs/xml/nginx/changes.xml b/docs/xml/nginx/changes.xml
index 7323d48e9..da1b954e4 100644
--- a/docs/xml/nginx/changes.xml
+++ b/docs/xml/nginx/changes.xml
@@ -9,6 +9,101 @@
<title lang="en">nginx changelog</title>
+<changes ver="0.1.18" date="09.02.2005">
+
+<change type="workaround">
+<para lang="ru">
+для совместимости с Solaris 10 в директивах devpoll_events и devpoll_changes
+значения по умолчанию уменьшены с 512 до 32.
+</para>
+<para lang="en">
+the default values of the devpoll_events and the devpoll_changes directives
+changed from 512 to 32 to be compatible with Solaris 10.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+директивы proxy_set_x_var и fastcgi_set_var не наследовались.
+</para>
+<para lang="en">
+the proxy_set_x_var and fastcgi_set_var directives were not inherited.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+в директиве rewrite, возвращающей редирект, аргументы присоединялись
+к URI через символ "&amp;" вместо "?".
+</para>
+<para lang="en">
+in the redirect rewrite directive the arguments were concatenated with URI
+by the "&amp;" rather than the "?".
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+строки для модуля ngx_http_geo_module без символа ";" во включённом файле
+игнорировались.
+</para>
+<para lang="en">
+the lines without trailing ";" in the file being included
+by the ngx_http_geo_module were silently ignored.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+модуль ngx_http_stub_status_module.
+</para>
+<para lang="en">
+the ngx_http_stub_status_module.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+неизвестный формат лог-файла в директиве access_log вызывал segmentation fault.
+</para>
+<para lang="en">
+the unknown log format in the access_log directive caused
+the segmentation fault.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+новый параметр document_root в директиве fastcgi_params.
+</para>
+<para lang="en">
+the new "document_root" parameter of the fastcgi_params directive.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+директива fastcgi_redirect_errors.
+</para>
+<para lang="en">
+the fastcgi_redirect_errors directive.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+новый модификатор break в директиве rewrite позволяет прекратить
+цикл rewrite/location и устанавливает текущую конфигурацию для запроса.
+</para>
+<para lang="en">
+the new "break" modifier of the "rewrite" directive allows to stop
+the rewrite/location cycle and sets the current configuration to the request.
+</para>
+</change>
+
+</changes>
+
+
<changes ver="0.1.17" date="03.02.2005">
<change type="feature">
@@ -126,7 +221,7 @@ keepalive_timeout запрещала использование keep-alive.
</para>
<para lang="en">
the "Connection: keep-alive" header were issued, even if the
-keepalive_timeout derective forbade the keep-alive use.
+keepalive_timeout directive forbade the keep-alive use.
</para>
</change>
@@ -164,7 +259,7 @@ are not used for the unix domain sockets.
директива rewrite поддерживает перезаписывание аргументов.
</para>
<para lang="en">
-the rewrite directive supports the agruments rewriting.
+the rewrite directive supports the arguments rewriting.
</para>
</change>
@@ -174,7 +269,7 @@ the rewrite directive supports the agruments rewriting.
ошибка появилась в 0.1.14.
</para>
<para lang="en">
-the response code 400 was returend for the POST request with the
+the response code 400 was returned for the POST request with the
"Content-Length: 0" header;
bug appeared in 0.1.14.
</para>
diff --git a/src/core/nginx.h b/src/core/nginx.h
index c6afc4599..dbadb45ed 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_
-#define NGINX_VER "nginx/0.1.17"
+#define NGINX_VER "nginx/0.1.18"
#define NGINX_VAR "NGINX"
#define NGX_NEWPID_EXT ".newbin"
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index e9cc24de5..436103a8c 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -48,7 +48,7 @@ static int argument_number[] = {
NGX_CONF_TAKE7
};
-static int ngx_conf_read_token(ngx_conf_t *cf);
+static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf);
char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
@@ -337,7 +337,7 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
}
-static int ngx_conf_read_token(ngx_conf_t *cf)
+static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf)
{
u_char *start, ch, *src, *dst;
int len;
@@ -361,7 +361,17 @@ static int ngx_conf_read_token(ngx_conf_t *cf)
if (b->pos >= b->last) {
if (cf->conf_file->file.offset
- >= ngx_file_size(&cf->conf_file->file.info)) {
+ >= ngx_file_size(&cf->conf_file->file.info))
+ {
+ if (cf->args->nelts > 0) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "unexpected end of file in %s:%d, "
+ "expecting \";\" or \"}\"",
+ cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
+
return NGX_CONF_FILE_DONE;
}
@@ -418,7 +428,7 @@ static int ngx_conf_read_token(ngx_conf_t *cf)
}
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "unexpected '%c' in %s:%d",
+ "unexpected \"%c\" in %s:%d",
ch, cf->conf_file->file.name.data,
cf->conf_file->line);
@@ -438,7 +448,7 @@ static int ngx_conf_read_token(ngx_conf_t *cf)
case '{':
if (cf->args->nelts == 0) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "unexpected '%c' in %s:%d",
+ "unexpected \"%c\" in %s:%d",
ch, cf->conf_file->file.name.data,
cf->conf_file->line);
return NGX_ERROR;
@@ -453,7 +463,7 @@ static int ngx_conf_read_token(ngx_conf_t *cf)
case '}':
if (cf->args->nelts > 0) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "unexpected '}' in %s:%d",
+ "unexpected \"}\" in %s:%d",
cf->conf_file->file.name.data,
cf->conf_file->line);
return NGX_ERROR;
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index b3fa5de35..e8f06fdfd 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -397,7 +397,6 @@ void ngx_close_connection(ngx_connection_t *c)
}
-
ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
{
ngx_uint_t level;
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
index 56d2e98d3..a30ff035b 100644
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -313,7 +313,7 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u)
sin->sin_family = AF_INET;
sin->sin_port = u->port;
- sin->sin_addr.s_addr = *(in_addr_t *)(h->h_addr_list[i]);
+ sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]);
peers->peer[i].sockaddr = (struct sockaddr *) sin;
peers->peer[i].socklen = sizeof(struct sockaddr_in);
diff --git a/src/core/ngx_radix_tree.c b/src/core/ngx_radix_tree.c
index 9493bab8a..e0ce095b0 100644
--- a/src/core/ngx_radix_tree.c
+++ b/src/core/ngx_radix_tree.c
@@ -11,8 +11,10 @@
static void *ngx_radix_alloc(ngx_radix_tree_t *tree);
-ngx_radix_tree_t *ngx_radix_tree_create(ngx_pool_t *pool)
+ngx_radix_tree_t *
+ngx_radix_tree_create(ngx_pool_t *pool, ngx_uint_t preallocate)
{
+ uint32_t key, mask, inc;
ngx_radix_tree_t *tree;
if (!(tree = ngx_palloc(pool, sizeof(ngx_radix_tree_t)))) {
@@ -33,12 +35,43 @@ ngx_radix_tree_t *ngx_radix_tree_create(ngx_pool_t *pool)
tree->root->parent = NULL;
tree->root->value = NGX_RADIX_NO_VALUE;
+ /*
+ * We preallocate the first nodes: 0, 1, 00, 01, 10, 11, 000, 001, etc.,
+ * to increase the TLB hits even if for the first lookup iterations.
+ * On the 32-bit platforms the 7 preallocated bits takes continuous 4K,
+ * 8 - 8K, 9 - 16K, etc.
+ */
+
+ mask = 0;
+ inc = 0x80000000;
+
+ while (preallocate--) {
+
+ key = 0;
+ mask >>= 1;
+ mask |= 0x80000000;
+
+ do {
+ if (ngx_radix32tree_insert(tree, key, mask, NGX_RADIX_NO_VALUE)
+ != NGX_OK)
+ {
+ return NULL;
+ }
+
+ key += inc;
+
+ } while (key);
+
+ inc >>= 1;
+ }
+
return tree;
}
-ngx_int_t ngx_radix32tree_insert(ngx_radix_tree_t *tree,
- uint32_t key, uint32_t mask, uintptr_t value)
+ngx_int_t
+ngx_radix32tree_insert(ngx_radix_tree_t *tree, uint32_t key, uint32_t mask,
+ uintptr_t value)
{
uint32_t bit;
ngx_radix_node_t *node, *next;
@@ -100,8 +133,8 @@ ngx_int_t ngx_radix32tree_insert(ngx_radix_tree_t *tree,
}
-ngx_int_t ngx_radix32tree_delete(ngx_radix_tree_t *tree,
- uint32_t key, uint32_t mask)
+ngx_int_t
+ngx_radix32tree_delete(ngx_radix_tree_t *tree, uint32_t key, uint32_t mask)
{
uint32_t bit;
ngx_radix_node_t *node;
@@ -158,7 +191,8 @@ ngx_int_t ngx_radix32tree_delete(ngx_radix_tree_t *tree,
}
-uintptr_t ngx_radix32tree_find(ngx_radix_tree_t *tree, uint32_t key)
+uintptr_t
+ngx_radix32tree_find(ngx_radix_tree_t *tree, uint32_t key)
{
uint32_t bit;
uintptr_t value;
@@ -187,7 +221,8 @@ uintptr_t ngx_radix32tree_find(ngx_radix_tree_t *tree, uint32_t key)
}
-static void *ngx_radix_alloc(ngx_radix_tree_t *tree)
+static void *
+ngx_radix_alloc(ngx_radix_tree_t *tree)
{
char *p;
diff --git a/src/core/ngx_radix_tree.h b/src/core/ngx_radix_tree.h
index c2d8a36a2..99c6eeaf2 100644
--- a/src/core/ngx_radix_tree.h
+++ b/src/core/ngx_radix_tree.h
@@ -33,11 +33,12 @@ typedef struct {
} ngx_radix_tree_t;
-ngx_radix_tree_t *ngx_radix_tree_create(ngx_pool_t *pool);
+ngx_radix_tree_t *ngx_radix_tree_create(ngx_pool_t *pool,
+ ngx_uint_t preallocate);
ngx_int_t ngx_radix32tree_insert(ngx_radix_tree_t *tree,
- uint32_t key, uint32_t mask, uintptr_t value);
+ uint32_t key, uint32_t mask, uintptr_t value);
ngx_int_t ngx_radix32tree_delete(ngx_radix_tree_t *tree,
- uint32_t key, uint32_t mask);
+ uint32_t key, uint32_t mask);
uintptr_t ngx_radix32tree_find(ngx_radix_tree_t *tree, uint32_t key);
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index aa61df7de..a9c60c46e 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -587,8 +587,8 @@ static char *ngx_devpoll_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_devpoll_conf_t *dpcf = conf;
- ngx_conf_init_unsigned_value(dpcf->changes, 512);
- ngx_conf_init_unsigned_value(dpcf->events, 512);
+ ngx_conf_init_unsigned_value(dpcf->changes, 32);
+ ngx_conf_init_unsigned_value(dpcf->events, 32);
return NGX_CONF_OK;
}
diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c
index 0554ee95f..623e13c16 100644
--- a/src/event/modules/ngx_select_module.c
+++ b/src/event/modules/ngx_select_module.c
@@ -347,8 +347,15 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
work_read_fd_set = master_read_fd_set;
work_write_fd_set = master_write_fd_set;
+#if 1
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "select read fd_set: %08Xd", *(int *) &work_read_fd_set);
+ /*
+ * (void *) disables "dereferencing type-punned
+ * pointer will break strict-aliasing rules
+ */
+ "select read fd_set: %08Xd",
+ *(int *) (void *) &work_read_fd_set);
+#endif
#if (NGX_WIN32)
ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp);
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c
index d809a77aa..c7f759553 100644
--- a/src/event/ngx_event_accept.c
+++ b/src/event/ngx_event_accept.c
@@ -142,7 +142,7 @@ void ngx_event_accept(ngx_event_t *ev)
(*ngx_stat_active)++;
#endif
- /* set a blocking mode for aio and non-blocking mode for the others */
+ /* set a blocking mode for aio and non-blocking mode for others */
if (ngx_inherited_nonblocking) {
if ((ngx_event_flags & NGX_USE_AIO_EVENT)) {
diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c
index 1a3e8f806..81798d315 100644
--- a/src/event/ngx_event_connect.c
+++ b/src/event/ngx_event_connect.c
@@ -10,7 +10,11 @@
#include <ngx_event_connect.h>
-ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc)
+#define NGX_RESOLVER_BUFSIZE 8192
+
+
+ngx_int_t
+ngx_event_connect_peer(ngx_peer_connection_t *pc)
{
int rc;
ngx_uint_t instance;
@@ -274,12 +278,18 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc)
if (err != NGX_EINPROGRESS && err != NGX_EAGAIN) {
ngx_connection_error(c, err, "connect() failed");
- if (ngx_close_socket(s) == -1) {
- ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
- ngx_close_socket_n " failed");
- }
+#if 0
+#undef sun
+ {
+ struct sockaddr_un *sun;
- c->fd = (ngx_socket_t) -1;
+ sun = (struct sockaddr_un *) peer->sockaddr;
+
+ ngx_log_error(NGX_LOG_ALERT, pc->log, 0,
+ "\"%s\", f:%d, l:%uz",
+ sun->sun_path, sun->sun_family, peer->socklen);
+ }
+#endif
return NGX_CONNECT_ERROR;
}
@@ -287,7 +297,9 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc)
if (ngx_add_conn) {
if (rc == -1) {
+
/* NGX_EINPROGRESS */
+
return NGX_AGAIN;
}
@@ -308,17 +320,11 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc)
if (ngx_blocking(s) == -1) {
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
ngx_blocking_n " failed");
-
- if (ngx_close_socket(s) == -1) {
- ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
- ngx_close_socket_n " failed");
- }
-
return NGX_ERROR;
}
/*
- * FreeBSD aio allows to post operation on non-connected socket.
+ * FreeBSD's aio allows to post an operation on non-connected socket.
* NT does not support it.
*
* TODO: check in Win32, etc. As workaround we can use NGX_ONESHOT_EVENT
@@ -330,10 +336,16 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc)
return NGX_OK;
}
- if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { /* kqueue */
+ if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
+
+ /* kqueue */
+
event = NGX_CLEAR_EVENT;
- } else { /* select, poll, /dev/poll */
+ } else {
+
+ /* select, poll, /dev/poll */
+
event = NGX_LEVEL_EVENT;
}
@@ -360,7 +372,8 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc)
}
-void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc)
+void
+ngx_event_connect_peer_failed(ngx_peer_connection_t *pc)
{
time_t now;
@@ -380,6 +393,4 @@ void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc)
}
pc->tries--;
-
- return;
}
diff --git a/src/event/ngx_event_connect.h b/src/event/ngx_event_connect.h
index 4f3ee2e27..48863abe5 100644
--- a/src/event/ngx_event_connect.h
+++ b/src/event/ngx_event_connect.h
@@ -48,21 +48,21 @@ struct ngx_peers_s {
typedef struct {
- ngx_peers_t *peers;
- ngx_uint_t cur_peer;
- ngx_uint_t tries;
+ ngx_peers_t *peers;
+ ngx_uint_t cur_peer;
+ ngx_uint_t tries;
- ngx_connection_t *connection;
+ ngx_connection_t *connection;
#if (NGX_THREADS)
- ngx_atomic_t *lock;
+ ngx_atomic_t *lock;
#endif
- int rcvbuf;
+ int rcvbuf;
- ngx_log_t *log;
+ ngx_log_t *log;
- unsigned cached:1;
- unsigned log_error:2; /* ngx_connection_log_error_e */
+ unsigned cached:1;
+ unsigned log_error:2; /* ngx_connection_log_error_e */
} ngx_peer_connection_t;
diff --git a/src/http/modules/ngx_http_fastcgi_handler.c b/src/http/modules/ngx_http_fastcgi_handler.c
index 828f7accc..43f99ca41 100644
--- a/src/http/modules/ngx_http_fastcgi_handler.c
+++ b/src/http/modules/ngx_http_fastcgi_handler.c
@@ -20,7 +20,7 @@ typedef struct {
ngx_str_t root;
ngx_str_t index;
- ngx_array_t vars;
+ ngx_array_t *vars;
ngx_str_t *location;
} ngx_http_fastcgi_loc_conf_t;
@@ -84,6 +84,7 @@ typedef struct {
#define NGX_HTTP_FASTCGI_GATEWAY_INTERFACE 0x0400
#define NGX_HTTP_FASTCGI_REQUEST_URI 0x0800
#define NGX_HTTP_FASTCGI_REDIRECT_STATUS 0x1000
+#define NGX_HTTP_FASTCGI_DOCUMENT_ROOT 0x2000
#define NGX_HTTP_FASTCGI_RESPONDER 1
@@ -123,22 +124,22 @@ static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r);
static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
- ngx_buf_t *buf);
+ ngx_buf_t *buf);
static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r,
- ngx_http_fastcgi_ctx_t *f);
+ ngx_http_fastcgi_ctx_t *f);
static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r);
static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
- ngx_int_t rc);
+ ngx_int_t rc);
static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
- void *data);
+ void *data);
static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_str_t ngx_http_fastcgi_methods[] = {
@@ -155,17 +156,17 @@ static ngx_http_header_t ngx_http_fastcgi_headers_in[] = {
{ ngx_string("Status"), offsetof(ngx_http_fastcgi_headers_in_t, status) },
{ ngx_string("Content-Type"),
- offsetof(ngx_http_fastcgi_headers_in_t, content_type) },
+ offsetof(ngx_http_fastcgi_headers_in_t, content_type) },
{ ngx_string("Content-Length"),
- offsetof(ngx_http_fastcgi_headers_in_t, content_length) },
+ offsetof(ngx_http_fastcgi_headers_in_t, content_length) },
{ ngx_string("X-Powered-By"),
- offsetof(ngx_http_fastcgi_headers_in_t, x_powered_by) },
+ offsetof(ngx_http_fastcgi_headers_in_t, x_powered_by) },
#if (NGX_HTTP_GZIP)
{ ngx_string("Content-Encoding"),
- offsetof(ngx_http_fastcgi_headers_in_t, content_encoding) },
+ offsetof(ngx_http_fastcgi_headers_in_t, content_encoding) },
#endif
{ ngx_null_string, 0 }
@@ -173,7 +174,7 @@ static ngx_http_header_t ngx_http_fastcgi_headers_in[] = {
static ngx_conf_post_t ngx_http_fastcgi_lowat_post =
- { ngx_http_fastcgi_lowat_check } ;
+ { ngx_http_fastcgi_lowat_check };
static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = {
{ ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
@@ -198,6 +199,7 @@ static ngx_conf_bitmask_t ngx_http_fastcgi_params_masks[] = {
{ ngx_string("redirect_status"), NGX_HTTP_FASTCGI_REDIRECT_STATUS },
{ ngx_string("request_uri"), NGX_HTTP_FASTCGI_REQUEST_URI },
+ { ngx_string("document_root"), NGX_HTTP_FASTCGI_DOCUMENT_ROOT },
{ ngx_null_string, 0 }
};
@@ -254,6 +256,13 @@ static ngx_command_t ngx_http_fastcgi_commands[] = {
offsetof(ngx_http_fastcgi_loc_conf_t, upstream.header_buffer_size),
NULL },
+ { ngx_string("fastcgi_redirect_errors"),
+ 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_fastcgi_loc_conf_t, upstream.redirect_errors),
+ NULL },
+
{ ngx_string("fastcgi_x_powered_by"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
@@ -352,7 +361,8 @@ ngx_module_t ngx_http_fastcgi_module = {
};
-static ngx_int_t ngx_http_fastcgi_handler(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_fastcgi_handler(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_http_upstream_t *u;
@@ -408,7 +418,8 @@ static ngx_int_t ngx_http_fastcgi_handler(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_fastcgi_create_request(ngx_http_request_t *r)
{
u_char ch, *pos, addr_text[INET_ADDRSTRLEN];
size_t size, len, index, padding, addr_len;
@@ -422,6 +433,7 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
struct sockaddr_in sin;
ngx_http_variable_t *var;
ngx_http_variable_value_t *value;
+ ngx_http_core_loc_conf_t *clcf;
ngx_http_core_main_conf_t *cmcf;
ngx_http_fastcgi_header_t *h;
ngx_http_fastcgi_loc_conf_t *flcf;
@@ -450,6 +462,12 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
return NGX_ERROR;
}
+#if (NGX_SUPPRESS_WARN)
+ clcf = NULL;
+ var = NULL;
+ vindex = NULL;
+#endif
+
if (r->upstream->method) {
len = 1 + 1 + sizeof("REQUEST_METHOD") - 1
@@ -496,6 +514,12 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
+ sizeof("REQUEST_URI") - 1 + r->unparsed_uri.len;
}
+ if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) {
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+ len += 1 + ((clcf->root.len > 127) ? 4 : 1)
+ + sizeof("DOCUMENT_ROOT") - 1 + clcf->root.len;
+ }
+
if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) {
len += 1 + ((r->uri.len + index > 127) ? 4 : 1)
+ sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ;
@@ -533,19 +557,21 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+ if (flcf->vars) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
- var = cmcf->variables.elts;
- vindex = flcf->vars.elts;
+ var = cmcf->variables.elts;
+ vindex = flcf->vars->elts;
- for (i = 0; i < flcf->vars.nelts; i++) {
+ for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, vindex[i]))) {
- continue;
- }
+ if (!(value = ngx_http_get_variable(r, vindex[i]))) {
+ continue;
+ }
- if (value->text.len) {
- len += 1 + 1 + var[vindex[i]].name.len + value->text.len;
+ if (value->text.len) {
+ len += 1 + 1 + var[vindex[i]].name.len + value->text.len;
+ }
}
}
@@ -785,6 +811,26 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
+ if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) {
+ *b->last++ = sizeof("DOCUMENT_ROOT") - 1;
+
+ len = clcf->root.len;
+ if (len > 127) {
+ *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80);
+ *b->last++ = (u_char) ((len >> 16) & 0xff);
+ *b->last++ = (u_char) ((len >> 8) & 0xff);
+ *b->last++ = (u_char) (len & 0xff);
+
+ } else {
+ *b->last++ = (u_char) len;
+ }
+
+ b->last = ngx_cpymem(b->last, "DOCUMENT_ROOT",
+ sizeof("DOCUMENT_ROOT") - 1);
+ b->last = ngx_cpymem(b->last, clcf->root.data, len);
+ }
+
+
if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) {
*b->last++ = sizeof("SCRIPT_NAME") - 1;
@@ -882,23 +928,25 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
- for (i = 0; i < flcf->vars.nelts; i++) {
+ if (flcf->vars) {
+ for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, vindex[i]))) {
- continue;
- }
+ if (!(value = ngx_http_get_variable(r, vindex[i]))) {
+ continue;
+ }
- if (value->text.len == 0) {
- continue;
- }
+ if (value->text.len == 0) {
+ continue;
+ }
- *b->last++ = (u_char) var[vindex[i]].name.len;
- *b->last++ = (u_char) value->text.len;
+ *b->last++ = (u_char) var[vindex[i]].name.len;
+ *b->last++ = (u_char) value->text.len;
- b->last = ngx_cpymem(b->last, var[vindex[i]].name.data,
- var[vindex[i]].name.len);
+ b->last = ngx_cpymem(b->last, var[vindex[i]].name.data,
+ var[vindex[i]].name.len);
- b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
+ b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
+ }
}
@@ -1091,7 +1139,8 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_fastcgi_reinit_request(ngx_http_request_t *r)
{
ngx_http_fastcgi_ctx_t *f;
@@ -1357,7 +1406,8 @@ static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_fastcgi_send_header(ngx_http_request_t *r)
{
ngx_uint_t i;
ngx_list_part_t *part;
@@ -1433,8 +1483,8 @@ static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
- ngx_buf_t *buf)
+static ngx_int_t
+ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
{
ngx_int_t rc;
ngx_buf_t *b, **prev;
@@ -1637,8 +1687,9 @@ static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
}
-static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r,
- ngx_http_fastcgi_ctx_t *f)
+static ngx_int_t
+ngx_http_fastcgi_process_record(ngx_http_request_t *r,
+ ngx_http_fastcgi_ctx_t *f)
{
u_char ch, *p;
ngx_http_upstream_t *u;
@@ -1746,7 +1797,8 @@ static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r,
}
-static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
+static void
+ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"abort http fastcgi request");
@@ -1755,8 +1807,8 @@ static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
}
-static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
- ngx_int_t rc)
+static void
+ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http fastcgi request");
@@ -1765,8 +1817,8 @@ static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
}
-static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_fastcgi_loc_conf_t *lcf = conf;
@@ -1829,8 +1881,8 @@ static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_fastcgi_loc_conf_t *lcf = conf;
@@ -1839,10 +1891,10 @@ static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
ngx_http_variable_t *var;
ngx_http_core_main_conf_t *cmcf;
- if (lcf->vars.elts == NULL) {
- if (ngx_array_init(&lcf->vars, cf->pool, 4,
- sizeof(ngx_http_variable_t *)) == NGX_ERROR)
- {
+ if (lcf->vars == NULL) {
+ lcf->vars = ngx_array_create(cf->pool, 4,
+ sizeof(ngx_http_variable_t *));
+ if (lcf->vars == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -1855,7 +1907,7 @@ static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
for (i = 0; i < cmcf->variables.nelts; i++) {
if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
- if (!(index = ngx_array_push(&lcf->vars))) {
+ if (!(index = ngx_array_push(lcf->vars))) {
return NGX_CONF_ERROR;
}
@@ -1870,8 +1922,8 @@ static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
- void *data)
+static char *
+ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data)
{
#if (NGX_FREEBSD)
ssize_t *np = data;
@@ -1899,7 +1951,8 @@ static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
}
-static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_fastcgi_loc_conf_t *conf;
@@ -1933,6 +1986,7 @@ static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
conf->upstream.max_temp_file_size = NGX_CONF_UNSET_SIZE;
conf->upstream.temp_file_write_size = NGX_CONF_UNSET_SIZE;
+ conf->upstream.redirect_errors = NGX_CONF_UNSET;
conf->upstream.x_powered_by = NGX_CONF_UNSET;
/* "fastcgi_cyclic_temp_file" is disabled */
@@ -1942,8 +1996,8 @@ static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
}
-static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_fastcgi_loc_conf_t *prev = parent;
ngx_http_fastcgi_loc_conf_t *conf = child;
@@ -1960,6 +2014,9 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_msec_value(conf->upstream.read_timeout,
prev->upstream.read_timeout, 60000);
+ ngx_conf_merge_msec_value(conf->upstream.redirect_errors,
+ prev->upstream.redirect_errors, 0);
+
ngx_conf_merge_msec_value(conf->upstream.x_powered_by,
prev->upstream.x_powered_by, 1);
@@ -2049,10 +2106,10 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
- prev->upstream.next_upstream,
- (NGX_CONF_BITMASK_SET
- |NGX_HTTP_UPSTREAM_FT_ERROR
- |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
+ prev->upstream.next_upstream,
+ (NGX_CONF_BITMASK_SET
+ |NGX_HTTP_UPSTREAM_FT_ERROR
+ |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
ngx_conf_merge_path_value(conf->upstream.temp_path,
prev->upstream.temp_path,
@@ -2061,15 +2118,15 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_bitmask_value(conf->params, prev->params,
- (NGX_CONF_BITMASK_SET
- |NGX_HTTP_FASTCGI_REMOTE_ADDR
- |NGX_HTTP_FASTCGI_REMOTE_USER
- |NGX_HTTP_FASTCGI_SERVER_NAME
- |NGX_HTTP_FASTCGI_SERVER_PORT
- |NGX_HTTP_FASTCGI_SCRIPT_NAME
- |NGX_HTTP_FASTCGI_AUTH_TYPE
- |NGX_HTTP_FASTCGI_REQUEST_URI
- |NGX_HTTP_FASTCGI_REDIRECT_STATUS));
+ (NGX_CONF_BITMASK_SET
+ |NGX_HTTP_FASTCGI_REMOTE_ADDR
+ |NGX_HTTP_FASTCGI_REMOTE_USER
+ |NGX_HTTP_FASTCGI_SERVER_NAME
+ |NGX_HTTP_FASTCGI_SERVER_PORT
+ |NGX_HTTP_FASTCGI_SCRIPT_NAME
+ |NGX_HTTP_FASTCGI_AUTH_TYPE
+ |NGX_HTTP_FASTCGI_REQUEST_URI
+ |NGX_HTTP_FASTCGI_REDIRECT_STATUS));
ngx_conf_merge_str_value(conf->root, prev->root, "");
@@ -2079,5 +2136,9 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_str_value(conf->index, prev->index, "");
+ if (conf->vars == NULL) {
+ conf->vars = prev->vars;
+ }
+
return NGX_CONF_OK;
}
diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c
index cd774894c..7d17f03ca 100644
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -91,7 +91,7 @@ static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (!(tree = ngx_radix_tree_create(cf->pool))) {
+ if (!(tree = ngx_radix_tree_create(cf->pool, 8))) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c
index b1f591c97..d3c721fda 100644
--- a/src/http/modules/ngx_http_rewrite_handler.c
+++ b/src/http/modules/ngx_http_rewrite_handler.c
@@ -47,6 +47,7 @@ typedef struct {
uintptr_t args:1;
uintptr_t redirect:1;
+ uintptr_t break_cycle:1;
ngx_str_t name;
} ngx_http_rewrite_regex_code_t;
@@ -121,18 +122,18 @@ struct ngx_http_rewrite_engine_s {
static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle);
static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
+static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf,
+ ngx_command_t *cmd, void *conf);
static void *ngx_http_rewrite_start_code(ngx_pool_t *pool,
- ngx_array_t **codes, size_t size);
+ ngx_array_t **codes, size_t size);
static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size,
- u_char **main);
+ void *code);
static ngx_command_t ngx_http_rewrite_commands[] = {
@@ -208,7 +209,8 @@ ngx_module_t ngx_http_rewrite_module = {
uintptr_t ngx_http_rewrite_exit_code = (uintptr_t) NULL;
-static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_rewrite_handler(ngx_http_request_t *r)
{
ngx_http_rewrite_code_pt code;
ngx_http_rewrite_engine_t *e;
@@ -259,7 +261,8 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
}
-static void ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
{
ngx_int_t rc;
ngx_uint_t n;
@@ -318,7 +321,9 @@ static void ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
e->buf.len = code->size;
if (code->uri) {
- r->uri_changed = 1;
+ if (!code->break_cycle) {
+ r->uri_changed = 1;
+ }
if (rc && (r->quoted_uri || r->plus_in_uri)) {
e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len,
@@ -348,7 +353,8 @@ static void ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_request_t *r;
ngx_http_rewrite_regex_end_code_t *code;
@@ -377,7 +383,7 @@ static void ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
} else {
if (code->args && r->args.len) {
- *e->pos++ = '&';
+ *e->pos++ = '?';
e->pos = ngx_cpymem(e->pos, r->args.data, r->args.len);
}
@@ -425,7 +431,8 @@ static void ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_copy_capture_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_copy_capture_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_rewrite_copy_capture_code_t *code;
@@ -450,7 +457,8 @@ static void ngx_http_rewrite_copy_capture_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_rewrite_copy_code_t *code;
@@ -467,7 +475,8 @@ static void ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_start_args_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_start_args_code(ngx_http_rewrite_engine_t *e)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http rewrite args");
@@ -477,7 +486,8 @@ static void ngx_http_rewrite_start_args_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_return_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_return_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_rewrite_return_code_t *code;
@@ -489,7 +499,8 @@ static void ngx_http_rewrite_return_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_rewrite_if_code_t *code;
@@ -514,7 +525,8 @@ static void ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_variable_value_t *value;
ngx_http_rewrite_var_code_t *code;
@@ -540,7 +552,8 @@ static void ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
{
u_char *ref;
size_t len;
@@ -625,13 +638,15 @@ static void ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_nop_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_nop_code(ngx_http_rewrite_engine_t *e)
{
e->ip += sizeof(uintptr_t);
}
-static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_rewrite_init(ngx_cycle_t *cycle)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
@@ -649,7 +664,8 @@ static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle)
}
-static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_rewrite_loc_conf_t *conf;
@@ -665,8 +681,8 @@ static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
}
-static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_rewrite_loc_conf_t *prev = parent;
ngx_http_rewrite_loc_conf_t *conf = child;
@@ -737,7 +753,8 @@ static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf,
}
-static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -793,6 +810,10 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (ngx_strcmp(value[3].data, "last") == 0) {
last = 1;
+ } else if (ngx_strcmp(value[3].data, "break") == 0) {
+ regex->break_cycle = 1;
+ last = 1;
+
} else if (ngx_strcmp(value[3].data, "redirect") == 0) {
regex->status = NGX_HTTP_MOVED_TEMPORARILY;
regex->redirect = 1;
@@ -824,7 +845,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
copy_capture = ngx_http_rewrite_add_code(lcf->codes,
sizeof(ngx_http_rewrite_copy_capture_code_t),
- (u_char **) &regex);
+ &regex);
if (copy_capture == NULL) {
return NGX_CONF_ERROR;
}
@@ -857,7 +878,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (!regex->redirect) {
code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t),
- (u_char **) &regex);
+ &regex);
if (code == NULL) {
return NGX_CONF_ERROR;
}
@@ -907,7 +928,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
copy = ngx_http_rewrite_add_code(lcf->codes,
sizeof(ngx_http_rewrite_copy_code_t) + size,
- (u_char **) &regex);
+ &regex);
if (copy == NULL) {
return NGX_CONF_ERROR;
}
@@ -939,7 +960,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
regex_end = ngx_http_rewrite_add_code(lcf->codes,
sizeof(ngx_http_rewrite_regex_end_code_t),
- (u_char **) &regex);
+ &regex);
if (regex_end == NULL) {
return NGX_CONF_ERROR;
}
@@ -951,7 +972,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (last) {
code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t),
- (u_char **) &regex);
+ &regex);
if (code == NULL) {
return NGX_CONF_ERROR;
}
@@ -966,9 +987,8 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-
-static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -996,7 +1016,8 @@ static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -1179,8 +1200,8 @@ static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -1266,8 +1287,8 @@ static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static void *ngx_http_rewrite_start_code(ngx_pool_t *pool,
- ngx_array_t **codes, size_t size)
+static void *
+ngx_http_rewrite_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size)
{
if (*codes == NULL) {
if (!(*codes = ngx_array_create(pool, 256, 1))) {
@@ -1279,10 +1300,10 @@ static void *ngx_http_rewrite_start_code(ngx_pool_t *pool,
}
-static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size,
- u_char **main)
+static void *
+ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size, void *code)
{
- u_char *elts;
+ u_char *elts, **p;
void *new;
elts = codes->elts;
@@ -1292,7 +1313,8 @@ static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size,
}
if (elts != codes->elts) {
- *main += (u_char *) codes->elts - elts;
+ p = code;
+ *p += (u_char *) codes->elts - elts;
}
return new;
diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c
new file mode 100644
index 000000000..3a35fe910
--- /dev/null
+++ b/src/http/modules/ngx_http_stub_status_module.c
@@ -0,0 +1,138 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
+
+
+static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+
+static ngx_command_t ngx_http_status_commands[] = {
+
+ { ngx_string("stub_status"),
+ NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+ ngx_http_set_status,
+ 0,
+ 0,
+ NULL },
+
+ ngx_null_command
+};
+
+
+
+ngx_http_module_t ngx_http_stub_status_module_ctx = {
+ NULL, /* pre conf */
+
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
+
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
+
+ NULL, /* create location configuration */
+ NULL /* merge location configuration */
+};
+
+
+ngx_module_t ngx_http_stub_status_module = {
+ NGX_MODULE,
+ &ngx_http_stub_status_module_ctx, /* module context */
+ ngx_http_status_commands, /* module directives */
+ NGX_HTTP_MODULE, /* module type */
+ NULL, /* init module */
+ NULL /* init process */
+};
+
+
+static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
+{
+ size_t size;
+ ngx_int_t rc;
+ uint32_t ap, hn, ac, rq, rd, wr;
+ ngx_buf_t *b;
+ ngx_chain_t out;
+
+ if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
+ return NGX_HTTP_NOT_ALLOWED;
+ }
+
+ rc = ngx_http_discard_body(r);
+
+ if (rc != NGX_OK && rc != NGX_AGAIN) {
+ return rc;
+ }
+
+ r->headers_out.content_type = ngx_list_push(&r->headers_out.headers);
+ if (r->headers_out.content_type == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ r->headers_out.content_type->key.len = 0;
+ r->headers_out.content_type->key.data = NULL;
+ r->headers_out.content_type->value.len = sizeof("text/plain") - 1;
+ r->headers_out.content_type->value.data = (u_char *) "text/plain";
+
+ if (r->method == NGX_HTTP_HEAD) {
+ r->headers_out.status = NGX_HTTP_OK;
+
+ rc = ngx_http_send_header(r);
+
+ if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
+ return rc;
+ }
+ }
+
+ size = sizeof("Active connections: \n") + NGX_INT32_LEN
+ + sizeof("server accepts handled requests\n") - 1
+ + 6 + 3 * NGX_INT32_LEN
+ + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_INT32_LEN;
+
+ if (!(b = ngx_create_temp_buf(r->pool, size))) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ out.buf = b;
+ out.next = NULL;
+
+ ap = *ngx_stat_accepted;
+ hn = *ngx_connection_counter;
+ ac = *ngx_stat_active;
+ rq = *ngx_stat_requests;
+ rd = *ngx_stat_reading;
+ wr = *ngx_stat_writing;
+
+ b->last = ngx_sprintf(b->last, "Active connections: %d \n", ac);
+
+ b->last = ngx_cpymem(b->last, "server accepts handled requests\n",
+ sizeof("server accepts handled requests\n") - 1);
+
+ b->last = ngx_sprintf(b->last, " %d %d %d \n", ap, hn, rq);
+
+ b->last = ngx_sprintf(b->last, "Reading: %d Writing: %d Waiting: %d \n",
+ rd, wr, ac - (rd + wr));
+
+ r->headers_out.status = NGX_HTTP_OK;
+ r->headers_out.content_length_n = b->last - b->pos;
+
+ b->last_buf = 1;
+
+ rc = ngx_http_send_header(r);
+
+ if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
+ return rc;
+ }
+
+ return ngx_http_output_filter(r, &out);;
+}
+
+
+static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_http_core_loc_conf_t *clcf;
+
+ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
+ clcf->handler = ngx_http_status_handler;
+
+ return NGX_CONF_OK;
+}
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index a195b45e4..d213d6929 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -1284,6 +1284,10 @@ static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_value(conf->lm_factor, prev->lm_factor, 0);
ngx_conf_merge_sec_value(conf->default_expires, prev->default_expires, 0);
+ if (conf->x_vars == NULL) {
+ conf->x_vars = prev->x_vars;
+ }
+
return NULL;
}
@@ -1389,10 +1393,10 @@ static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
ngx_http_variable_t *var;
ngx_http_core_main_conf_t *cmcf;
- if (lcf->x_vars.elts == NULL) {
- if (ngx_array_init(&lcf->x_vars, cf->pool, 4,
- sizeof(ngx_http_variable_t *)) == NGX_ERROR)
- {
+ if (lcf->x_vars == NULL) {
+ lcf->x_vars = ngx_array_create(cf->pool, 4,
+ sizeof(ngx_http_variable_t *));
+ if (lcf->x_vars == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -1405,7 +1409,7 @@ static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
for (i = 0; i < cmcf->variables.nelts; i++) {
if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
- if (!(index = ngx_array_push(&lcf->x_vars))) {
+ if (!(index = ngx_array_push(lcf->x_vars))) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 28d7971df..f950258dc 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -87,7 +87,7 @@ typedef struct {
ngx_path_t *cache_path;
ngx_path_t *temp_path;
- ngx_array_t x_vars;
+ ngx_array_t *x_vars;
ngx_http_busy_lock_t *busy_lock;
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index cf5195368..e2fe01554 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -100,6 +100,11 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
r = p->request;
uc = p->lcf->upstream;
+#if (NGX_SUPPRESS_WARN)
+ var = NULL;
+ index = NULL;
+#endif
+
if (p->upstream->method) {
len = http_methods[p->upstream->method - 1].len;
@@ -169,20 +174,22 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
}
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+ if (p->lcf->x_vars) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
- var = cmcf->variables.elts;
- index = p->lcf->x_vars.elts;
+ var = cmcf->variables.elts;
+ index = p->lcf->x_vars->elts;
- for (i = 0; i < p->lcf->x_vars.nelts; i++) {
+ for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, index[i]))) {
- continue;
- }
+ if (!(value = ngx_http_get_variable(r, index[i]))) {
+ continue;
+ }
- if (value->text.len) {
- len += sizeof("X-") - 1 + var[index[i]].name.len + sizeof(": ") - 1
- + value->text.len + sizeof(CRLF) - 1;
+ if (value->text.len) {
+ len += sizeof("X-") - 1 + var[index[i]].name.len
+ + sizeof(": ") - 1 + value->text.len + sizeof(CRLF) - 1;
+ }
}
}
@@ -356,26 +363,28 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
}
- for (i = 0; i < p->lcf->x_vars.nelts; i++) {
+ if (p->lcf->x_vars) {
+ for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, index[i]))) {
- continue;
- }
+ if (!(value = ngx_http_get_variable(r, index[i]))) {
+ continue;
+ }
- if (value->text.len == 0) {
- continue;
- }
+ if (value->text.len == 0) {
+ continue;
+ }
- *b->last++ = 'X'; *b->last++ = '-';
+ *b->last++ = 'X'; *b->last++ = '-';
- b->last = ngx_cpymem(b->last, var[index[i]].name.data,
- var[index[i]].name.len);
+ b->last = ngx_cpymem(b->last, var[index[i]].name.data,
+ var[index[i]].name.len);
- *b->last++ = ':'; *b->last++ = ' ';
+ *b->last++ = ':'; *b->last++ = ' ';
- b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
+ b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
- *b->last++ = CR; *b->last++ = LF;
+ *b->last++ = CR; *b->last++ = LF;
+ }
}
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 10fcb8790..8b66a7911 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -20,39 +20,39 @@
static void ngx_http_core_phase_event_handler(ngx_event_t *rev);
static void ngx_http_core_run_phases(ngx_http_request_t *r);
static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r,
- ngx_array_t *locations, size_t len);
+ ngx_array_t *locations, size_t len);
static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
- void *dummy);
+ void *dummy);
static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
- void *dummy);
+ void *dummy);
static int ngx_http_core_cmp_locations(const void *first, const void *second);
static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
- void *conf);
+ void *conf);
static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_core_error_page(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,
- void *conf);
+ void *conf);
static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
@@ -360,7 +360,8 @@ ngx_module_t ngx_http_core_module = {
};
-void ngx_http_handler(ngx_http_request_t *r)
+void
+ngx_http_handler(ngx_http_request_t *r)
{
r->connection->log->action = NULL;
@@ -416,12 +417,11 @@ void ngx_http_handler(ngx_http_request_t *r)
r->uri_changes = 11;
ngx_http_core_run_phases(r);
-
- return;
}
-static void ngx_http_core_phase_event_handler(ngx_event_t *ev)
+static void
+ngx_http_core_phase_event_handler(ngx_event_t *ev)
{
ngx_connection_t *c;
ngx_http_request_t *r;
@@ -432,12 +432,11 @@ static void ngx_http_core_phase_event_handler(ngx_event_t *ev)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "phase event handler");
ngx_http_core_run_phases(r);
-
- return;
}
-static void ngx_http_core_run_phases(ngx_http_request_t *r)
+static void
+ngx_http_core_run_phases(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_http_handler_pt *h;
@@ -541,11 +540,11 @@ static void ngx_http_core_run_phases(ngx_http_request_t *r)
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
- return;
}
-ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r)
+ngx_int_t
+ngx_http_find_location_config(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_http_core_loc_conf_t *clcf;
@@ -618,8 +617,9 @@ ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r,
- ngx_array_t *locations, size_t len)
+static ngx_int_t
+ngx_http_core_find_location(ngx_http_request_t *r,
+ ngx_array_t *locations, size_t len)
{
ngx_int_t n, rc;
ngx_uint_t i, found, noregex;
@@ -752,7 +752,8 @@ static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r,
}
-ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r)
+ngx_int_t
+ngx_http_set_content_type(ngx_http_request_t *r)
{
u_char c, *p, *exten;
uint32_t key;
@@ -832,7 +833,8 @@ ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r)
}
-ngx_int_t ngx_http_send_header(ngx_http_request_t *r)
+ngx_int_t
+ngx_http_send_header(ngx_http_request_t *r)
{
if (r->main) {
return NGX_OK;
@@ -843,11 +845,12 @@ ngx_int_t ngx_http_send_header(ngx_http_request_t *r)
r->headers_out.status_line.len = 0;
}
- return (*ngx_http_top_header_filter)(r);
+ return ngx_http_top_header_filter(r);
}
-ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
+ngx_int_t
+ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
ngx_int_t rc;
@@ -859,7 +862,7 @@ ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
if (rc == NGX_ERROR) {
- /* NGX_ERROR could be returned by any filter */
+ /* NGX_ERROR may be returned by any filter */
r->connection->write->error = 1;
}
@@ -868,7 +871,8 @@ ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
-int ngx_http_redirect(ngx_http_request_t *r, int redirect)
+ngx_int_t
+ngx_http_redirect(ngx_http_request_t *r, int redirect)
{
/* STUB */
@@ -879,7 +883,8 @@ int ngx_http_redirect(ngx_http_request_t *r, int redirect)
}
-ngx_int_t ngx_http_set_exten(ngx_http_request_t *r)
+ngx_int_t
+ngx_http_set_exten(ngx_http_request_t *r)
{
ngx_int_t i;
@@ -912,9 +917,12 @@ ngx_int_t ngx_http_set_exten(ngx_http_request_t *r)
}
-ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
- ngx_str_t *uri, ngx_str_t *args)
+ngx_int_t
+ngx_http_internal_redirect(ngx_http_request_t *r,
+ ngx_str_t *uri, ngx_str_t *args)
{
+ ngx_http_core_srv_conf_t *cscf;
+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"internal redirect: \"%V\"", uri);
@@ -930,7 +938,7 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
if (r->err_ctx) {
- /* allocate the new modules contexts */
+ /* allocate the new module's contexts */
r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
if (r->ctx == NULL) {
@@ -944,6 +952,9 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
}
+ cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
+ r->loc_conf = cscf->ctx->loc_conf;
+
r->phase = 0;
r->phase_handler = 0;
r->content_handler = NULL;
@@ -956,7 +967,8 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
#if 0 /* STUB: test the delay http handler */
-int ngx_http_delay_handler(ngx_http_request_t *r)
+ngx_int_t
+ngx_http_delay_handler(ngx_http_request_t *r)
{
static int on;
@@ -976,7 +988,8 @@ int ngx_http_delay_handler(ngx_http_request_t *r)
#endif
-ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf)
+ngx_http_variable_t *
+ngx_http_add_variable(ngx_conf_t *cf)
{
ngx_http_variable_t *var;
ngx_http_core_main_conf_t *cmcf;
@@ -1001,8 +1014,8 @@ ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf)
}
-ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r,
- ngx_uint_t index)
+ngx_http_variable_value_t *
+ngx_http_get_variable(ngx_http_request_t *r, ngx_uint_t index)
{
ngx_http_variable_t *v;
ngx_http_core_main_conf_t *cmcf;
@@ -1023,35 +1036,38 @@ ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r,
}
-static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
- void *dummy)
+static char *
+ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
{
- int m;
- char *rv;
- ngx_http_module_t *module;
- ngx_conf_t save;
- ngx_http_conf_ctx_t *ctx, *http_ctx;
- ngx_http_core_main_conf_t *cmcf;
- ngx_http_core_srv_conf_t *cscf, **cscfp;
-
- ngx_test_null(ctx,
- ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
- NGX_CONF_ERROR);
+ int m;
+ char *rv;
+ void *mconf;
+ ngx_conf_t save;
+ ngx_http_module_t *module;
+ ngx_http_conf_ctx_t *ctx, *http_ctx;
+ ngx_http_core_srv_conf_t *cscf, **cscfp;
+ ngx_http_core_main_conf_t *cmcf;
+
+ if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+ return NGX_CONF_ERROR;
+ }
http_ctx = cf->ctx;
ctx->main_conf = http_ctx->main_conf;
/* the server{}'s srv_conf */
- ngx_test_null(ctx->srv_conf,
- ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
- NGX_CONF_ERROR);
+ ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
+ if (ctx->srv_conf == NULL) {
+ return NGX_CONF_ERROR;
+ }
/* the server{}'s loc_conf */
- ngx_test_null(ctx->loc_conf,
- ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
- NGX_CONF_ERROR);
+ ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
+ if (ctx->loc_conf == NULL) {
+ return NGX_CONF_ERROR;
+ }
for (m = 0; ngx_modules[m]; m++) {
if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
@@ -1061,27 +1077,38 @@ static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
module = ngx_modules[m]->ctx;
if (module->create_srv_conf) {
- ngx_test_null(ctx->srv_conf[ngx_modules[m]->ctx_index],
- module->create_srv_conf(cf),
- NGX_CONF_ERROR);
+ if (!(mconf = module->create_srv_conf(cf))) {
+ return NGX_CONF_ERROR;
+ }
+
+ ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf;
}
if (module->create_loc_conf) {
- ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index],
- module->create_loc_conf(cf),
- NGX_CONF_ERROR);
+ if (!(mconf = module->create_loc_conf(cf))) {
+ return NGX_CONF_ERROR;
+ }
+
+ ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf;
}
}
- /* create links of the srv_conf's */
+
+ /* the server configuration context */
cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
cscf->ctx = ctx;
+
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
- ngx_test_null(cscfp, ngx_push_array(&cmcf->servers), NGX_CONF_ERROR);
+
+ if (!(cscfp = ngx_array_push(&cmcf->servers))) {
+ return NGX_CONF_ERROR;
+ }
+
*cscfp = cscf;
+
/* parse inside server{} */
save = *cf;
@@ -1103,8 +1130,8 @@ static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
- void *dummy)
+static char *
+ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
{
char *rv;
ngx_int_t m;
@@ -1205,7 +1232,7 @@ static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
if (pclcf->name.len == 0) {
cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
- if (!(clcfp = ngx_push_array(&cscf->locations))) {
+ if (!(clcfp = ngx_array_push(&cscf->locations))) {
return NGX_CONF_ERROR;
}
@@ -1268,7 +1295,8 @@ static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static int ngx_http_core_cmp_locations(const void *one, const void *two)
+static int
+ngx_http_core_cmp_locations(const void *one, const void *two)
{
ngx_int_t rc;
ngx_http_core_loc_conf_t *first, *second;
@@ -1321,7 +1349,8 @@ static int ngx_http_core_cmp_locations(const void *one, const void *two)
}
-static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *rv;
ngx_conf_t save;
@@ -1338,8 +1367,8 @@ static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
- void *conf)
+static char *
+ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
{
ngx_http_core_loc_conf_t *lcf = conf;
@@ -1381,7 +1410,8 @@ static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
}
-static void *ngx_http_core_create_main_conf(ngx_conf_t *cf)
+static void *
+ngx_http_core_create_main_conf(ngx_conf_t *cf)
{
ngx_http_core_main_conf_t *cmcf;
@@ -1402,7 +1432,8 @@ static void *ngx_http_core_create_main_conf(ngx_conf_t *cf)
}
-static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
+static char *
+ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
{
ngx_http_core_main_conf_t *cmcf = conf;
@@ -1418,25 +1449,38 @@ static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
}
-static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf)
+static void *
+ngx_http_core_create_srv_conf(ngx_conf_t *cf)
{
ngx_http_core_srv_conf_t *cscf;
- ngx_test_null(cscf,
- ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)),
- NGX_CONF_ERROR);
+ if (!(cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)))) {
+ return NGX_CONF_ERROR;
+ }
+
/*
- *
* set by ngx_pcalloc():
+ *
* conf->client_large_buffers.num = 0;
*/
- ngx_init_array(cscf->locations, cf->pool,
- 5, sizeof(void *), NGX_CONF_ERROR);
- ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t),
- NGX_CONF_ERROR);
- ngx_init_array(cscf->server_names, cf->pool,
- 5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR);
+ if (ngx_array_init(&cscf->locations, cf->pool, 5, sizeof(void *))
+ == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
+
+ if (ngx_array_init(&cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t))
+ == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
+
+ if (ngx_array_init(&cscf->server_names, cf->pool, 5,
+ sizeof(ngx_http_server_name_t)) == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
cscf->post_accept_timeout = NGX_CONF_UNSET_MSEC;
@@ -1449,49 +1493,56 @@ static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf)
}
-static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_core_srv_conf_t *prev = parent;
ngx_http_core_srv_conf_t *conf = child;
- ngx_http_listen_t *l;
- ngx_http_server_name_t *n;
+ ngx_http_listen_t *ls;
+ ngx_http_server_name_t *sn;
ngx_http_core_main_conf_t *cmcf;
/* TODO: it does not merge, it inits only */
if (conf->listen.nelts == 0) {
- ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR);
- l->addr = INADDR_ANY;
+ if (!(ls = ngx_array_push(&conf->listen))) {
+ return NGX_CONF_ERROR;
+ }
+
+ ls->addr = INADDR_ANY;
#if (NGX_WIN32)
- l->port = 80;
+ ls->port = 80;
#else
/* STUB: getuid() should be cached */
- l->port = (getuid() == 0) ? 80 : 8000;
+ ls->port = (getuid() == 0) ? 80 : 8000;
#endif
- l->family = AF_INET;
+ ls->family = AF_INET;
}
if (conf->server_names.nelts == 0) {
- ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR);
- ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN),
- NGX_CONF_ERROR);
+ if (!(sn = ngx_array_push(&conf->server_names))) {
+ return NGX_CONF_ERROR;
+ }
- if (gethostname((char *) n->name.data, NGX_MAXHOSTNAMELEN) == -1) {
+ if (!(sn->name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN))) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (gethostname((char *) sn->name.data, NGX_MAXHOSTNAMELEN) == -1) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
"gethostname() failed");
return NGX_CONF_ERROR;
}
- n->name.len = ngx_strlen(n->name.data);
- n->core_srv_conf = conf;
- n->wildcard = 0;
+ sn->name.len = ngx_strlen(sn->name.data);
+ sn->core_srv_conf = conf;
+ sn->wildcard = 0;
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
- if (cmcf->max_server_name_len < n->name.len) {
- cmcf->max_server_name_len = n->name.len;
+ if (cmcf->max_server_name_len < sn->name.len) {
+ cmcf->max_server_name_len = sn->name.len;
}
}
@@ -1517,19 +1568,20 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
}
ngx_conf_merge_unsigned_value(conf->restrict_host_names,
- prev->restrict_host_names, 0);
+ prev->restrict_host_names, 0);
return NGX_CONF_OK;
}
-static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_core_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_core_loc_conf_t *lcf;
- ngx_test_null(lcf,
- ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)),
- NGX_CONF_ERROR);
+ if (!(lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)))) {
+ return NGX_CONF_ERROR;
+ }
/*
* set by ngx_pcalloc():
@@ -1569,7 +1621,7 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf)
}
-static ngx_http_type_t default_types[] = {
+static ngx_http_type_t ngx_http_core_default_types[] = {
{ ngx_string("html"), ngx_string("text/html") },
{ ngx_string("gif"), ngx_string("image/gif") },
{ ngx_string("jpg"), ngx_string("image/jpeg") },
@@ -1577,14 +1629,16 @@ static ngx_http_type_t default_types[] = {
};
-static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
+static char *
+ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
void *parent, void *child)
{
ngx_http_core_loc_conf_t *prev = parent;
ngx_http_core_loc_conf_t *conf = child;
- int i, key;
- ngx_http_type_t *t;
+ uint32_t key;
+ ngx_uint_t i;
+ ngx_http_type_t *type;
ngx_conf_merge_str_value(conf->root, prev->root, "html");
@@ -1597,25 +1651,29 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
conf->types = prev->types;
} else {
- ngx_test_null(conf->types,
- ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME
- * sizeof(ngx_array_t)),
- NGX_CONF_ERROR);
+ conf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME
+ * sizeof(ngx_array_t));
+ if (conf->types == NULL) {
+ return NGX_CONF_ERROR;
+ }
for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) {
- ngx_init_array(conf->types[i], cf->pool,
- 5, sizeof(ngx_http_type_t), NGX_CONF_ERROR);
+ if (ngx_array_init(&conf->types[i], cf->pool, 5,
+ sizeof(ngx_http_type_t)) == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
}
- for (i = 0; default_types[i].exten.len; i++) {
- ngx_http_types_hash_key(key, default_types[i].exten);
+ for (i = 0; ngx_http_core_default_types[i].exten.len; i++) {
+ ngx_http_types_hash_key(key,
+ ngx_http_core_default_types[i].exten);
- ngx_test_null(t, ngx_push_array(&conf->types[key]),
- NGX_CONF_ERROR);
- t->exten.len = default_types[i].exten.len;
- t->exten.data = default_types[i].exten.data;
- t->type.len = default_types[i].type.len;
- t->type.data = default_types[i].type.data;
+ if (!(type = ngx_array_push(&conf->types[key]))) {
+ return NGX_CONF_ERROR;
+ }
+
+ *type = ngx_http_core_default_types[i];
}
}
}
@@ -1633,7 +1691,7 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
}
ngx_conf_merge_str_value(conf->default_type,
- prev->default_type, "text/plain");
+ prev->default_type, "text/plain");
ngx_conf_merge_size_value(conf->client_max_body_size,
prev->client_max_body_size, 1 * 1024 * 1024);
@@ -1665,7 +1723,7 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
ngx_garbage_collector_temp_handler, cf);
ngx_conf_merge_value(conf->reset_timedout_connection,
- prev->reset_timedout_connection, 0);
+ prev->reset_timedout_connection, 0);
ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
if (conf->open_files == NULL) {
@@ -1676,8 +1734,8 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
}
-static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_srv_conf_t *scf = conf;
@@ -1746,6 +1804,7 @@ static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
}
ls->addr = inet_addr((const char *) addr);
+
if (ls->addr == INADDR_NONE) {
h = gethostbyname((const char *) addr);
@@ -1763,8 +1822,8 @@ static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_srv_conf_t *scf = conf;
@@ -1814,7 +1873,8 @@ static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_loc_conf_t *lcf = conf;
@@ -1854,18 +1914,18 @@ static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_loc_conf_t *lcf = conf;
- int overwrite;
+ ngx_int_t overwrite;
ngx_uint_t i, n;
ngx_str_t *value;
ngx_http_err_page_t *err;
if (lcf->error_pages == NULL) {
- lcf->error_pages = ngx_create_array(cf->pool, 5,
+ lcf->error_pages = ngx_array_create(cf->pool, 4,
sizeof(ngx_http_err_page_t));
if (lcf->error_pages == NULL) {
return NGX_CONF_ERROR;
@@ -1899,11 +1959,12 @@ static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
}
for (i = 1; i < cf->args->nelts - n; i++) {
- if (!(err = ngx_push_array(lcf->error_pages))) {
+ if (!(err = ngx_array_push(lcf->error_pages))) {
return NGX_CONF_ERROR;
}
err->status = ngx_atoi(value[i].data, value[i].len);
+
if (err->status == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid value \"%V\"", &value[i]);
@@ -1925,8 +1986,8 @@ static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_loc_conf_t *lcf = conf;
@@ -1939,6 +2000,7 @@ static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
value = cf->args->elts;
lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
+
if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
return "invalid value";
}
@@ -1952,6 +2014,7 @@ static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
}
lcf->keepalive_header = ngx_parse_time(&value[2], 1);
+
if (lcf->keepalive_header == NGX_ERROR) {
return "invalid value";
}
@@ -1964,8 +2027,8 @@ static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_loc_conf_t *lcf = conf;
@@ -1977,7 +2040,8 @@ static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
+static char *
+ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
{
#if (NGX_FREEBSD)
ssize_t *np = data;
diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c
index d4f906f1a..722b9f806 100644
--- a/src/http/ngx_http_log_handler.c
+++ b/src/http/ngx_http_log_handler.c
@@ -859,7 +859,10 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
}
}
- return NGX_CONF_OK;
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "unknown log format \"%V\"", &name);
+
+ return NGX_CONF_ERROR;
}
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index 5702a855a..a26937497 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -193,7 +193,8 @@ static ngx_str_t error_pages[] = {
};
-ngx_int_t ngx_http_special_response_handler(ngx_http_request_t *r, int error)
+ngx_int_t
+ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
{
ngx_int_t rc;
ngx_uint_t err, i, msie_padding;
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 11e0f3105..5b8312130 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -12,29 +12,26 @@
static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev);
static void ngx_http_upstream_connect(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
+ ngx_http_upstream_t *u);
static void ngx_http_upstream_reinit(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
+ ngx_http_upstream_t *u);
static void ngx_http_upstream_send_request(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
+ ngx_http_upstream_t *u);
static void ngx_http_upstream_send_request_handler(ngx_event_t *wev);
static void ngx_http_upstream_process_header(ngx_event_t *rev);
static void ngx_http_upstream_send_response(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
+ ngx_http_upstream_t *u);
static void ngx_http_upstream_process_body(ngx_event_t *ev);
static void ngx_http_upstream_dummy_handler(ngx_event_t *wev);
static void ngx_http_upstream_next(ngx_http_request_t *r,
- ngx_http_upstream_t *u,
- ngx_uint_t ft_type);
+ ngx_http_upstream_t *u, ngx_uint_t ft_type);
static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
- ngx_http_upstream_t *u,
- ngx_int_t rc);
+ ngx_http_upstream_t *u, ngx_int_t rc);
static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r,
- uintptr_t data);
-static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op);
-
+ uintptr_t data);
+static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r,
+ u_char *buf, ngx_http_log_op_t *op);
static ngx_int_t ngx_http_upstream_add_log_formats(ngx_conf_t *cf);
@@ -77,7 +74,8 @@ char *ngx_http_upstream_header_errors[] = {
};
-void ngx_http_upstream_init(ngx_http_request_t *r)
+void
+ngx_http_upstream_init(ngx_http_request_t *r)
{
ngx_connection_t *c;
ngx_http_upstream_t *u;
@@ -148,7 +146,8 @@ void ngx_http_upstream_init(ngx_http_request_t *r)
}
-static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev)
+static void
+ngx_http_upstream_check_broken_connection(ngx_event_t *ev)
{
int n;
char buf[1];
@@ -265,8 +264,8 @@ static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev)
}
-static void ngx_http_upstream_connect(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
+static void
+ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
ngx_int_t rc;
ngx_connection_t *c;
@@ -350,8 +349,8 @@ static void ngx_http_upstream_connect(ngx_http_request_t *r,
}
-static void ngx_http_upstream_reinit(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
+static void
+ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
ngx_chain_t *cl;
@@ -400,14 +399,11 @@ static void ngx_http_upstream_reinit(ngx_http_request_t *r,
}
ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
-
- u->status = 0;
- u->status_count = 0;
}
-static void ngx_http_upstream_send_request(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
+static void
+ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
int rc;
ngx_connection_t *c;
@@ -505,7 +501,8 @@ static void ngx_http_upstream_send_request(ngx_http_request_t *r,
}
-static void ngx_http_upstream_send_request_handler(ngx_event_t *wev)
+static void
+ngx_http_upstream_send_request_handler(ngx_event_t *wev)
{
ngx_connection_t *c;
ngx_http_request_t *r;
@@ -534,13 +531,17 @@ static void ngx_http_upstream_send_request_handler(ngx_event_t *wev)
}
-static void ngx_http_upstream_process_header(ngx_event_t *rev)
+static void
+ngx_http_upstream_process_header(ngx_event_t *rev)
{
- ssize_t n;
- ngx_int_t rc;
- ngx_connection_t *c;
- ngx_http_request_t *r;
- ngx_http_upstream_t *u;
+ ssize_t n;
+ ngx_int_t rc;
+ ngx_uint_t i;
+ ngx_connection_t *c;
+ ngx_http_request_t *r;
+ ngx_http_upstream_t *u;
+ ngx_http_err_page_t *err_page;
+ ngx_http_core_loc_conf_t *clcf;
c = rev->data;
r = c->data;
@@ -657,12 +658,31 @@ static void ngx_http_upstream_process_header(ngx_event_t *rev)
/* rc == NGX_OK */
+ if (r->headers_out.status >= NGX_HTTP_BAD_REQUEST
+ && u->conf->redirect_errors
+ && r->err_ctx == NULL)
+ {
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+ if (clcf->error_pages) {
+
+ err_page = clcf->error_pages->elts;
+ for (i = 0; i < clcf->error_pages->nelts; i++) {
+ if (err_page[i].status == (ngx_int_t) r->headers_out.status) {
+ ngx_http_upstream_finalize_request(r, u,
+ r->headers_out.status);
+ return;
+ }
+ }
+ }
+ }
+
ngx_http_upstream_send_response(r, u);
}
-static void ngx_http_upstream_send_response(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
+static void
+ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
ngx_int_t rc;
ngx_event_pipe_t *p;
@@ -802,7 +822,8 @@ static void ngx_http_upstream_send_response(ngx_http_request_t *r,
}
-static void ngx_http_upstream_process_body(ngx_event_t *ev)
+static void
+ngx_http_upstream_process_body(ngx_event_t *ev)
{
ngx_connection_t *c;
ngx_http_request_t *r;
@@ -891,16 +912,17 @@ static void ngx_http_upstream_process_body(ngx_event_t *ev)
}
-static void ngx_http_upstream_dummy_handler(ngx_event_t *wev)
+static void
+ngx_http_upstream_dummy_handler(ngx_event_t *wev)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
"http upstream dummy handler");
}
-static void ngx_http_upstream_next(ngx_http_request_t *r,
- ngx_http_upstream_t *u,
- ngx_uint_t ft_type)
+static void
+ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
+ ngx_uint_t ft_type)
{
ngx_uint_t status;
@@ -994,9 +1016,9 @@ static void ngx_http_upstream_next(ngx_http_request_t *r,
}
-static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
- ngx_http_upstream_t *u,
- ngx_int_t rc)
+static void
+ngx_http_upstream_finalize_request(ngx_http_request_t *r,
+ ngx_http_upstream_t *u, ngx_int_t rc)
{
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http upstream request: %i", rc);
@@ -1057,8 +1079,8 @@ static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
}
-static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r,
- uintptr_t data)
+static size_t
+ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, uintptr_t data)
{
if (r->upstream) {
return r->upstream->states.nelts * (3 + 2);
@@ -1068,8 +1090,9 @@ static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r,
}
-static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op)
+static u_char *
+ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf,
+ ngx_http_log_op_t *op)
{
ngx_uint_t i;
ngx_http_upstream_t *u;
@@ -1103,7 +1126,8 @@ static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf,
}
-u_char *ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len)
+u_char *
+ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len)
{
u_char *p;
ngx_int_t escape;
@@ -1177,7 +1201,8 @@ u_char *ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len)
}
-static ngx_int_t ngx_http_upstream_add_log_formats(ngx_conf_t *cf)
+static ngx_int_t
+ngx_http_upstream_add_log_formats(ngx_conf_t *cf)
{
ngx_http_log_op_name_t *op;
diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
index 79ba2a194..c722152a2 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -54,6 +54,7 @@ typedef struct {
ngx_bufs_t bufs;
+ ngx_flag_t redirect_errors;
ngx_flag_t x_powered_by;
ngx_flag_t cyclic_temp_file;
@@ -95,13 +96,6 @@ struct ngx_http_upstream_s {
ngx_http_log_ctx_t *saved_log_ctx;
ngx_log_handler_pt saved_log_handler;
- /* used to parse an upstream HTTP header */
- ngx_uint_t status;
- u_char *status_start;
- u_char *status_end;
- ngx_uint_t status_count;
- ngx_uint_t parse_state;
-
ngx_http_upstream_state_t *state;
ngx_array_t states; /* of ngx_http_upstream_state_t */