nginx-0.1.18-RELEASE import

*) Workaround: the default values of the devpoll_events and the
       devpoll_changes directives changed from 512 to 32 to be compatible
       with Solaris 10.

    *) Bugfix: the proxy_set_x_var and fastcgi_set_var directives were not
       inherited.

    *) Bugfix: in the redirect rewrite directive the arguments were
       concatenated with URI by the "&" rather than the "?".

    *) Bugfix: the lines without trailing ";" in the file being included by
       the ngx_http_geo_module were silently ignored.

    *) Feature: the ngx_http_stub_status_module.

    *) Bugfix: the unknown log format in the access_log directive caused
       the segmentation fault.

    *) Feature: the new "document_root" parameter of the fastcgi_params
       directive.

    *) Feature: the fastcgi_redirect_errors directive.

    *) Feature: the new "break" modifier of the "rewrite" directive allows
       to stop the rewrite/location cycle and sets the current
       configuration to the request.
This commit is contained in:
Igor Sysoev 2005-02-09 14:31:07 +00:00
parent 9ef28fa32a
commit aa8286101a
30 changed files with 907 additions and 413 deletions

View File

@ -2,6 +2,8 @@
# Copyright (C) Igor Sysoev # Copyright (C) Igor Sysoev
LINK="\$(CC)"
ngx_include_opt="-I " ngx_include_opt="-I "
ngx_compile_opt="-c" ngx_compile_opt="-c"
ngx_objout="-o " ngx_objout="-o "
@ -56,7 +58,7 @@ else
# # Compaq C V6.5-207 # # Compaq C V6.5-207
# #
# . auto/cc/ccc # . auto/cc/ccc
ngx_include_opt="-I " ngx_include_opt="-I"
;; ;;
# acc) # acc)

View File

@ -27,8 +27,13 @@ fi
# optimizations # optimizations
#CFLAGS="$CFLAGS -O2 -fomit-frame-pointer" #NGX_GCC_OPT="-O2"
#CFLAGS="$CFLAGS -Os -fomit-frame-pointer" #NGX_GCC_OPT="-Os"
NGX_GCC_OPT="-O"
CFLAGS="$CFLAGS $NGX_GCC_OPT"
#CFLAGS="$CFLAGS -fomit-frame-pointer"
case $CPU in case $CPU in
pentium) pentium)
@ -83,7 +88,9 @@ fi
# warnings # warnings
CFLAGS="$CFLAGS -O -W" # -W requires at least -O
CFLAGS="$CFLAGS ${NGX_GCC_OPT:-O} -W"
CFLAGS="$CFLAGS -Wall -Wpointer-arith" CFLAGS="$CFLAGS -Wall -Wpointer-arith"
#CFLAGS="$CFLAGS -Wconversion" #CFLAGS="$CFLAGS -Wconversion"
#CFLAGS="$CFLAGS -Winline" #CFLAGS="$CFLAGS -Winline"
@ -103,5 +110,3 @@ CFLAGS="$CFLAGS -g"
if [ ".$CPP" = "." ]; then if [ ".$CPP" = "." ]; then
CPP="$CC -E" CPP="$CC -E"
fi fi
LINK="\$(CC)"

View File

@ -68,5 +68,3 @@ CFLAGS="$CFLAGS -Werror"
# debug # debug
CFLAGS="$CFLAGS -g" CFLAGS="$CFLAGS -g"
LINK="\$(CC)"

View File

@ -69,8 +69,6 @@ NGX_BUILD_PCH="-fhq=$NGX_OBJS/ngx_config.pch"
NGX_USE_PCH="-fh=$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 # the link flags, built target is NT GUI mode application
CORE_LINK="$CORE_LINK -l=nt_win" CORE_LINK="$CORE_LINK -l=nt_win"

View File

@ -156,6 +156,12 @@ fi
#HTTP_SRCS="$HTTP_SRCS $HTPP_CACHE_SRCS" #HTTP_SRCS="$HTTP_SRCS $HTPP_CACHE_SRCS"
#HTTP_SRCS="$HTTP_SRCS $HTPP_FILE_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 if [ -r $NGX_OBJS/auto ]; then
. $NGX_OBJS/auto . $NGX_OBJS/auto
fi fi

View File

@ -58,6 +58,9 @@ HTTP_REWRITE=YES
HTTP_PROXY=YES HTTP_PROXY=YES
HTTP_FASTCGI=YES HTTP_FASTCGI=YES
# STUB
HTTP_STUB_STATUS=NO
IMAP=NO IMAP=NO
NGX_MODULES= NGX_MODULES=
@ -131,6 +134,9 @@ do
--without-http_proxy_module) HTTP_PROXY=NO ;; --without-http_proxy_module) HTTP_PROXY=NO ;;
--without-http_fastcgi_module) HTTP_FASTCGI=NO ;; --without-http_fastcgi_module) HTTP_FASTCGI=NO ;;
# STUB
--with-http_stub_status_module) HTTP_STUB_STATUS=YES ;;
--with-imap) IMAP=YES ;; --with-imap) IMAP=YES ;;
--with-module=*) NGX_MODULES="$NGX_MODULES $values" ;; --with-module=*) NGX_MODULES="$NGX_MODULES $values" ;;

View File

@ -9,6 +9,101 @@
<title lang="en">nginx changelog</title> <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"> <changes ver="0.1.17" date="03.02.2005">
<change type="feature"> <change type="feature">
@ -126,7 +221,7 @@ keepalive_timeout
</para> </para>
<para lang="en"> <para lang="en">
the "Connection: keep-alive" header were issued, even if the 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> </para>
</change> </change>
@ -164,7 +259,7 @@ are not used for the unix domain sockets.
ÄÉÒÅËÔÉ×Á rewrite ÐÏÄÄÅÒÖÉ×ÁÅÔ ÐÅÒÅÚÁÐÉÓÙ×ÁÎÉÅ ÁÒÇÕÍÅÎÔÏ×. ÄÉÒÅËÔÉ×Á rewrite ÐÏÄÄÅÒÖÉ×ÁÅÔ ÐÅÒÅÚÁÐÉÓÙ×ÁÎÉÅ ÁÒÇÕÍÅÎÔÏ×.
</para> </para>
<para lang="en"> <para lang="en">
the rewrite directive supports the agruments rewriting. the rewrite directive supports the arguments rewriting.
</para> </para>
</change> </change>
@ -174,7 +269,7 @@ the rewrite directive supports the agruments rewriting.
ÏÛÉÂËÁ ÐÏÑ×ÉÌÁÓØ × 0.1.14. ÏÛÉÂËÁ ÐÏÑ×ÉÌÁÓØ × 0.1.14.
</para> </para>
<para lang="en"> <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; "Content-Length: 0" header;
bug appeared in 0.1.14. bug appeared in 0.1.14.
</para> </para>

View File

@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_ #define _NGINX_H_INCLUDED_
#define NGINX_VER "nginx/0.1.17" #define NGINX_VER "nginx/0.1.18"
#define NGINX_VAR "NGINX" #define NGINX_VAR "NGINX"
#define NGX_NEWPID_EXT ".newbin" #define NGX_NEWPID_EXT ".newbin"

View File

@ -48,7 +48,7 @@ static int argument_number[] = {
NGX_CONF_TAKE7 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) 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; u_char *start, ch, *src, *dst;
int len; int len;
@ -361,7 +361,17 @@ static int ngx_conf_read_token(ngx_conf_t *cf)
if (b->pos >= b->last) { if (b->pos >= b->last) {
if (cf->conf_file->file.offset 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; 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, 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, ch, cf->conf_file->file.name.data,
cf->conf_file->line); cf->conf_file->line);
@ -438,7 +448,7 @@ static int ngx_conf_read_token(ngx_conf_t *cf)
case '{': case '{':
if (cf->args->nelts == 0) { if (cf->args->nelts == 0) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 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, ch, cf->conf_file->file.name.data,
cf->conf_file->line); cf->conf_file->line);
return NGX_ERROR; return NGX_ERROR;
@ -453,7 +463,7 @@ static int ngx_conf_read_token(ngx_conf_t *cf)
case '}': case '}':
if (cf->args->nelts > 0) { if (cf->args->nelts > 0) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 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->file.name.data,
cf->conf_file->line); cf->conf_file->line);
return NGX_ERROR; return NGX_ERROR;

View File

@ -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_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
{ {
ngx_uint_t level; ngx_uint_t level;

View File

@ -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_family = AF_INET;
sin->sin_port = u->port; 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].sockaddr = (struct sockaddr *) sin;
peers->peer[i].socklen = sizeof(struct sockaddr_in); peers->peer[i].socklen = sizeof(struct sockaddr_in);

View File

@ -11,8 +11,10 @@
static void *ngx_radix_alloc(ngx_radix_tree_t *tree); 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; ngx_radix_tree_t *tree;
if (!(tree = ngx_palloc(pool, sizeof(ngx_radix_tree_t)))) { 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->parent = NULL;
tree->root->value = NGX_RADIX_NO_VALUE; 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; return tree;
} }
ngx_int_t ngx_radix32tree_insert(ngx_radix_tree_t *tree, ngx_int_t
uint32_t key, uint32_t mask, uintptr_t value) ngx_radix32tree_insert(ngx_radix_tree_t *tree, uint32_t key, uint32_t mask,
uintptr_t value)
{ {
uint32_t bit; uint32_t bit;
ngx_radix_node_t *node, *next; 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, ngx_int_t
uint32_t key, uint32_t mask) ngx_radix32tree_delete(ngx_radix_tree_t *tree, uint32_t key, uint32_t mask)
{ {
uint32_t bit; uint32_t bit;
ngx_radix_node_t *node; 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; uint32_t bit;
uintptr_t value; 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; char *p;

View File

@ -33,11 +33,12 @@ typedef struct {
} ngx_radix_tree_t; } 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, 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, 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); uintptr_t ngx_radix32tree_find(ngx_radix_tree_t *tree, uint32_t key);

View File

@ -587,8 +587,8 @@ static char *ngx_devpoll_init_conf(ngx_cycle_t *cycle, void *conf)
{ {
ngx_devpoll_conf_t *dpcf = conf; ngx_devpoll_conf_t *dpcf = conf;
ngx_conf_init_unsigned_value(dpcf->changes, 512); ngx_conf_init_unsigned_value(dpcf->changes, 32);
ngx_conf_init_unsigned_value(dpcf->events, 512); ngx_conf_init_unsigned_value(dpcf->events, 32);
return NGX_CONF_OK; return NGX_CONF_OK;
} }

View File

@ -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_read_fd_set = master_read_fd_set;
work_write_fd_set = master_write_fd_set; work_write_fd_set = master_write_fd_set;
#if 1
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 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) #if (NGX_WIN32)
ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp); ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp);

View File

@ -142,7 +142,7 @@ void ngx_event_accept(ngx_event_t *ev)
(*ngx_stat_active)++; (*ngx_stat_active)++;
#endif #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_inherited_nonblocking) {
if ((ngx_event_flags & NGX_USE_AIO_EVENT)) { if ((ngx_event_flags & NGX_USE_AIO_EVENT)) {

View File

@ -10,7 +10,11 @@
#include <ngx_event_connect.h> #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; int rc;
ngx_uint_t instance; 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) { if (err != NGX_EINPROGRESS && err != NGX_EAGAIN) {
ngx_connection_error(c, err, "connect() failed"); ngx_connection_error(c, err, "connect() failed");
if (ngx_close_socket(s) == -1) { #if 0
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, #undef sun
ngx_close_socket_n " failed"); {
} 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; 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 (ngx_add_conn) {
if (rc == -1) { if (rc == -1) {
/* NGX_EINPROGRESS */ /* NGX_EINPROGRESS */
return NGX_AGAIN; return NGX_AGAIN;
} }
@ -308,17 +320,11 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc)
if (ngx_blocking(s) == -1) { if (ngx_blocking(s) == -1) {
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
ngx_blocking_n " failed"); 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; 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. * NT does not support it.
* *
* TODO: check in Win32, etc. As workaround we can use NGX_ONESHOT_EVENT * 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; 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; event = NGX_CLEAR_EVENT;
} else { /* select, poll, /dev/poll */ } else {
/* select, poll, /dev/poll */
event = NGX_LEVEL_EVENT; 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; time_t now;
@ -380,6 +393,4 @@ void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc)
} }
pc->tries--; pc->tries--;
return;
} }

View File

@ -48,21 +48,21 @@ struct ngx_peers_s {
typedef struct { typedef struct {
ngx_peers_t *peers; ngx_peers_t *peers;
ngx_uint_t cur_peer; ngx_uint_t cur_peer;
ngx_uint_t tries; ngx_uint_t tries;
ngx_connection_t *connection; ngx_connection_t *connection;
#if (NGX_THREADS) #if (NGX_THREADS)
ngx_atomic_t *lock; ngx_atomic_t *lock;
#endif #endif
int rcvbuf; int rcvbuf;
ngx_log_t *log; ngx_log_t *log;
unsigned cached:1; unsigned cached:1;
unsigned log_error:2; /* ngx_connection_log_error_e */ unsigned log_error:2; /* ngx_connection_log_error_e */
} ngx_peer_connection_t; } ngx_peer_connection_t;

View File

@ -20,7 +20,7 @@ typedef struct {
ngx_str_t root; ngx_str_t root;
ngx_str_t index; ngx_str_t index;
ngx_array_t vars; ngx_array_t *vars;
ngx_str_t *location; ngx_str_t *location;
} ngx_http_fastcgi_loc_conf_t; } ngx_http_fastcgi_loc_conf_t;
@ -84,6 +84,7 @@ typedef struct {
#define NGX_HTTP_FASTCGI_GATEWAY_INTERFACE 0x0400 #define NGX_HTTP_FASTCGI_GATEWAY_INTERFACE 0x0400
#define NGX_HTTP_FASTCGI_REQUEST_URI 0x0800 #define NGX_HTTP_FASTCGI_REQUEST_URI 0x0800
#define NGX_HTTP_FASTCGI_REDIRECT_STATUS 0x1000 #define NGX_HTTP_FASTCGI_REDIRECT_STATUS 0x1000
#define NGX_HTTP_FASTCGI_DOCUMENT_ROOT 0x2000
#define NGX_HTTP_FASTCGI_RESPONDER 1 #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_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);
static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, 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, 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_abort_request(ngx_http_request_t *r);
static void ngx_http_fastcgi_finalize_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, 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, 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, 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 void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_fastcgi_merge_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[] = { 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("Status"), offsetof(ngx_http_fastcgi_headers_in_t, status) },
{ ngx_string("Content-Type"), { 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"), { 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"), { 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) #if (NGX_HTTP_GZIP)
{ ngx_string("Content-Encoding"), { ngx_string("Content-Encoding"),
offsetof(ngx_http_fastcgi_headers_in_t, content_encoding) }, offsetof(ngx_http_fastcgi_headers_in_t, content_encoding) },
#endif #endif
{ ngx_null_string, 0 } { 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 = 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[] = { static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = {
{ ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, { 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("redirect_status"), NGX_HTTP_FASTCGI_REDIRECT_STATUS },
{ ngx_string("request_uri"), NGX_HTTP_FASTCGI_REQUEST_URI }, { ngx_string("request_uri"), NGX_HTTP_FASTCGI_REQUEST_URI },
{ ngx_string("document_root"), NGX_HTTP_FASTCGI_DOCUMENT_ROOT },
{ ngx_null_string, 0 } { 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), offsetof(ngx_http_fastcgi_loc_conf_t, upstream.header_buffer_size),
NULL }, 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_string("fastcgi_x_powered_by"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot, 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_int_t rc;
ngx_http_upstream_t *u; 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]; u_char ch, *pos, addr_text[INET_ADDRSTRLEN];
size_t size, len, index, padding, addr_len; 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; struct sockaddr_in sin;
ngx_http_variable_t *var; ngx_http_variable_t *var;
ngx_http_variable_value_t *value; ngx_http_variable_value_t *value;
ngx_http_core_loc_conf_t *clcf;
ngx_http_core_main_conf_t *cmcf; ngx_http_core_main_conf_t *cmcf;
ngx_http_fastcgi_header_t *h; ngx_http_fastcgi_header_t *h;
ngx_http_fastcgi_loc_conf_t *flcf; 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; return NGX_ERROR;
} }
#if (NGX_SUPPRESS_WARN)
clcf = NULL;
var = NULL;
vindex = NULL;
#endif
if (r->upstream->method) { if (r->upstream->method) {
len = 1 + 1 + sizeof("REQUEST_METHOD") - 1 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; + 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) { if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) {
len += 1 + ((r->uri.len + index > 127) ? 4 : 1) len += 1 + ((r->uri.len + index > 127) ? 4 : 1)
+ sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ; + 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; var = cmcf->variables.elts;
vindex = flcf->vars.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]))) { if (!(value = ngx_http_get_variable(r, vindex[i]))) {
continue; continue;
} }
if (value->text.len) { if (value->text.len) {
len += 1 + 1 + var[vindex[i]].name.len + 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) { if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) {
*b->last++ = sizeof("SCRIPT_NAME") - 1; *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]))) { if (!(value = ngx_http_get_variable(r, vindex[i]))) {
continue; 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 = 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);
} }
if (value->text.len == 0) {
continue;
}
*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, 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; 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_uint_t i;
ngx_list_part_t *part; 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, static ngx_int_t
ngx_buf_t *buf) ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
{ {
ngx_int_t rc; ngx_int_t rc;
ngx_buf_t *b, **prev; 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, static ngx_int_t
ngx_http_fastcgi_ctx_t *f) ngx_http_fastcgi_process_record(ngx_http_request_t *r,
ngx_http_fastcgi_ctx_t *f)
{ {
u_char ch, *p; u_char ch, *p;
ngx_http_upstream_t *u; 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, ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"abort http fastcgi request"); "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, static void
ngx_int_t rc) 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, ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http fastcgi request"); "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, static char *
void *conf) ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_http_fastcgi_loc_conf_t *lcf = 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, static char *
void *conf) ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_http_fastcgi_loc_conf_t *lcf = 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_variable_t *var;
ngx_http_core_main_conf_t *cmcf; ngx_http_core_main_conf_t *cmcf;
if (lcf->vars.elts == NULL) { if (lcf->vars == NULL) {
if (ngx_array_init(&lcf->vars, cf->pool, 4, lcf->vars = ngx_array_create(cf->pool, 4,
sizeof(ngx_http_variable_t *)) == NGX_ERROR) sizeof(ngx_http_variable_t *));
{ if (lcf->vars == NULL) {
return NGX_CONF_ERROR; 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++) { for (i = 0; i < cmcf->variables.nelts; i++) {
if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) { 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; 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, static char *
void *data) ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data)
{ {
#if (NGX_FREEBSD) #if (NGX_FREEBSD)
ssize_t *np = data; 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; 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.max_temp_file_size = NGX_CONF_UNSET_SIZE;
conf->upstream.temp_file_write_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; conf->upstream.x_powered_by = NGX_CONF_UNSET;
/* "fastcgi_cyclic_temp_file" is disabled */ /* "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, static char *
void *parent, void *child) 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 *prev = parent;
ngx_http_fastcgi_loc_conf_t *conf = child; 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, ngx_conf_merge_msec_value(conf->upstream.read_timeout,
prev->upstream.read_timeout, 60000); 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, ngx_conf_merge_msec_value(conf->upstream.x_powered_by,
prev->upstream.x_powered_by, 1); 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, ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
prev->upstream.next_upstream, prev->upstream.next_upstream,
(NGX_CONF_BITMASK_SET (NGX_CONF_BITMASK_SET
|NGX_HTTP_UPSTREAM_FT_ERROR |NGX_HTTP_UPSTREAM_FT_ERROR
|NGX_HTTP_UPSTREAM_FT_TIMEOUT)); |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
ngx_conf_merge_path_value(conf->upstream.temp_path, ngx_conf_merge_path_value(conf->upstream.temp_path,
prev->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_merge_bitmask_value(conf->params, prev->params,
(NGX_CONF_BITMASK_SET (NGX_CONF_BITMASK_SET
|NGX_HTTP_FASTCGI_REMOTE_ADDR |NGX_HTTP_FASTCGI_REMOTE_ADDR
|NGX_HTTP_FASTCGI_REMOTE_USER |NGX_HTTP_FASTCGI_REMOTE_USER
|NGX_HTTP_FASTCGI_SERVER_NAME |NGX_HTTP_FASTCGI_SERVER_NAME
|NGX_HTTP_FASTCGI_SERVER_PORT |NGX_HTTP_FASTCGI_SERVER_PORT
|NGX_HTTP_FASTCGI_SCRIPT_NAME |NGX_HTTP_FASTCGI_SCRIPT_NAME
|NGX_HTTP_FASTCGI_AUTH_TYPE |NGX_HTTP_FASTCGI_AUTH_TYPE
|NGX_HTTP_FASTCGI_REQUEST_URI |NGX_HTTP_FASTCGI_REQUEST_URI
|NGX_HTTP_FASTCGI_REDIRECT_STATUS)); |NGX_HTTP_FASTCGI_REDIRECT_STATUS));
ngx_conf_merge_str_value(conf->root, prev->root, ""); 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, ""); ngx_conf_merge_str_value(conf->index, prev->index, "");
if (conf->vars == NULL) {
conf->vars = prev->vars;
}
return NGX_CONF_OK; return NGX_CONF_OK;
} }

View File

@ -91,7 +91,7 @@ static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR; 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; return NGX_CONF_ERROR;
} }

View File

@ -47,6 +47,7 @@ typedef struct {
uintptr_t args:1; uintptr_t args:1;
uintptr_t redirect:1; uintptr_t redirect:1;
uintptr_t break_cycle:1;
ngx_str_t name; ngx_str_t name;
} ngx_http_rewrite_regex_code_t; } 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 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);
static char *ngx_http_rewrite_merge_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(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, 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, static char *ngx_http_rewrite_if(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, static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf,
void *conf); ngx_command_t *cmd, void *conf);
static void *ngx_http_rewrite_start_code(ngx_pool_t *pool, 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, 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[] = { 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; 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_code_pt code;
ngx_http_rewrite_engine_t *e; 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_int_t rc;
ngx_uint_t n; 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; e->buf.len = code->size;
if (code->uri) { if (code->uri) {
r->uri_changed = 1; if (!code->break_cycle) {
r->uri_changed = 1;
}
if (rc && (r->quoted_uri || r->plus_in_uri)) { if (rc && (r->quoted_uri || r->plus_in_uri)) {
e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len, 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_request_t *r;
ngx_http_rewrite_regex_end_code_t *code; 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 { } else {
if (code->args && r->args.len) { if (code->args && r->args.len) {
*e->pos++ = '&'; *e->pos++ = '?';
e->pos = ngx_cpymem(e->pos, r->args.data, r->args.len); 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; 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; 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, ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http rewrite args"); "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; 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; 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_variable_value_t *value;
ngx_http_rewrite_var_code_t *code; 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; u_char *ref;
size_t len; 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); 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_handler_pt *h;
ngx_http_core_main_conf_t *cmcf; 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; 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, static char *
void *parent, void *child) 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 *prev = parent;
ngx_http_rewrite_loc_conf_t *conf = child; 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; 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) { if (ngx_strcmp(value[3].data, "last") == 0) {
last = 1; 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) { } else if (ngx_strcmp(value[3].data, "redirect") == 0) {
regex->status = NGX_HTTP_MOVED_TEMPORARILY; regex->status = NGX_HTTP_MOVED_TEMPORARILY;
regex->redirect = 1; 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, copy_capture = ngx_http_rewrite_add_code(lcf->codes,
sizeof(ngx_http_rewrite_copy_capture_code_t), sizeof(ngx_http_rewrite_copy_capture_code_t),
(u_char **) &regex); &regex);
if (copy_capture == NULL) { if (copy_capture == NULL) {
return NGX_CONF_ERROR; 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) { if (!regex->redirect) {
code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t), code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t),
(u_char **) &regex); &regex);
if (code == NULL) { if (code == NULL) {
return NGX_CONF_ERROR; 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, copy = ngx_http_rewrite_add_code(lcf->codes,
sizeof(ngx_http_rewrite_copy_code_t) + size, sizeof(ngx_http_rewrite_copy_code_t) + size,
(u_char **) &regex); &regex);
if (copy == NULL) { if (copy == NULL) {
return NGX_CONF_ERROR; 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, regex_end = ngx_http_rewrite_add_code(lcf->codes,
sizeof(ngx_http_rewrite_regex_end_code_t), sizeof(ngx_http_rewrite_regex_end_code_t),
(u_char **) &regex); &regex);
if (regex_end == NULL) { if (regex_end == NULL) {
return NGX_CONF_ERROR; 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) { if (last) {
code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t), code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t),
(u_char **) &regex); &regex);
if (code == NULL) { if (code == NULL) {
return NGX_CONF_ERROR; 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 *
static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
void *conf)
{ {
ngx_http_rewrite_loc_conf_t *lcf = 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; 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, static char *
void *conf) ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_http_rewrite_loc_conf_t *lcf = conf; ngx_http_rewrite_loc_conf_t *lcf = conf;
@ -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, static void *
ngx_array_t **codes, size_t size) ngx_http_rewrite_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size)
{ {
if (*codes == NULL) { if (*codes == NULL) {
if (!(*codes = ngx_array_create(pool, 256, 1))) { 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, static void *
u_char **main) ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size, void *code)
{ {
u_char *elts; u_char *elts, **p;
void *new; void *new;
elts = codes->elts; 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) { if (elts != codes->elts) {
*main += (u_char *) codes->elts - elts; p = code;
*p += (u_char *) codes->elts - elts;
} }
return new; return new;

View File

@ -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;
}

View File

@ -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_value(conf->lm_factor, prev->lm_factor, 0);
ngx_conf_merge_sec_value(conf->default_expires, prev->default_expires, 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; 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_variable_t *var;
ngx_http_core_main_conf_t *cmcf; ngx_http_core_main_conf_t *cmcf;
if (lcf->x_vars.elts == NULL) { if (lcf->x_vars == NULL) {
if (ngx_array_init(&lcf->x_vars, cf->pool, 4, lcf->x_vars = ngx_array_create(cf->pool, 4,
sizeof(ngx_http_variable_t *)) == NGX_ERROR) sizeof(ngx_http_variable_t *));
{ if (lcf->x_vars == NULL) {
return NGX_CONF_ERROR; 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++) { for (i = 0; i < cmcf->variables.nelts; i++) {
if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) { 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; return NGX_CONF_ERROR;
} }

View File

@ -87,7 +87,7 @@ typedef struct {
ngx_path_t *cache_path; ngx_path_t *cache_path;
ngx_path_t *temp_path; ngx_path_t *temp_path;
ngx_array_t x_vars; ngx_array_t *x_vars;
ngx_http_busy_lock_t *busy_lock; ngx_http_busy_lock_t *busy_lock;

View File

@ -100,6 +100,11 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
r = p->request; r = p->request;
uc = p->lcf->upstream; uc = p->lcf->upstream;
#if (NGX_SUPPRESS_WARN)
var = NULL;
index = NULL;
#endif
if (p->upstream->method) { if (p->upstream->method) {
len = http_methods[p->upstream->method - 1].len; 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; var = cmcf->variables.elts;
index = p->lcf->x_vars.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]))) { if (!(value = ngx_http_get_variable(r, index[i]))) {
continue; continue;
} }
if (value->text.len) { if (value->text.len) {
len += sizeof("X-") - 1 + var[index[i]].name.len + sizeof(": ") - 1 len += sizeof("X-") - 1 + var[index[i]].name.len
+ value->text.len + sizeof(CRLF) - 1; + 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]))) { if (!(value = ngx_http_get_variable(r, index[i]))) {
continue; continue;
}
if (value->text.len == 0) {
continue;
}
*b->last++ = 'X'; *b->last++ = '-';
b->last = ngx_cpymem(b->last, var[index[i]].name.data,
var[index[i]].name.len);
*b->last++ = ':'; *b->last++ = ' ';
b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
*b->last++ = CR; *b->last++ = LF;
} }
if (value->text.len == 0) {
continue;
}
*b->last++ = 'X'; *b->last++ = '-';
b->last = ngx_cpymem(b->last, var[index[i]].name.data,
var[index[i]].name.len);
*b->last++ = ':'; *b->last++ = ' ';
b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
*b->last++ = CR; *b->last++ = LF;
} }

View File

@ -20,39 +20,39 @@
static void ngx_http_core_phase_event_handler(ngx_event_t *rev); 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 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, 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 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);
static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
static char *ngx_http_core_merge_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 void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
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); void *parent, void *child);
static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, 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, 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 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, 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, 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, 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, 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_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, 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, 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, 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); 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; r->connection->log->action = NULL;
@ -416,12 +417,11 @@ void ngx_http_handler(ngx_http_request_t *r)
r->uri_changes = 11; r->uri_changes = 11;
ngx_http_core_run_phases(r); 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_connection_t *c;
ngx_http_request_t *r; 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_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "phase event handler");
ngx_http_core_run_phases(r); 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_int_t rc;
ngx_http_handler_pt *h; 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_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
ngx_http_finalize_request(r, NGX_HTTP_NOT_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_int_t rc;
ngx_http_core_loc_conf_t *clcf; 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, static ngx_int_t
ngx_array_t *locations, size_t len) ngx_http_core_find_location(ngx_http_request_t *r,
ngx_array_t *locations, size_t len)
{ {
ngx_int_t n, rc; ngx_int_t n, rc;
ngx_uint_t i, found, noregex; 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; u_char c, *p, *exten;
uint32_t key; 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) { if (r->main) {
return NGX_OK; 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; 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; 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) { 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; 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 */ /* 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; 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_int_t
ngx_str_t *uri, ngx_str_t *args) 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, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"internal redirect: \"%V\"", uri); "internal redirect: \"%V\"", uri);
@ -930,7 +938,7 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
if (r->err_ctx) { 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); r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
if (r->ctx == NULL) { 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); 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 = 0;
r->phase_handler = 0; r->phase_handler = 0;
r->content_handler = NULL; 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 */ #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; static int on;
@ -976,7 +988,8 @@ int ngx_http_delay_handler(ngx_http_request_t *r)
#endif #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_variable_t *var;
ngx_http_core_main_conf_t *cmcf; 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_http_variable_value_t *
ngx_uint_t index) ngx_http_get_variable(ngx_http_request_t *r, ngx_uint_t index)
{ {
ngx_http_variable_t *v; ngx_http_variable_t *v;
ngx_http_core_main_conf_t *cmcf; 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, static char *
void *dummy) ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
{ {
int m; int m;
char *rv; char *rv;
ngx_http_module_t *module; void *mconf;
ngx_conf_t save; ngx_conf_t save;
ngx_http_conf_ctx_t *ctx, *http_ctx; ngx_http_module_t *module;
ngx_http_core_main_conf_t *cmcf; ngx_http_conf_ctx_t *ctx, *http_ctx;
ngx_http_core_srv_conf_t *cscf, **cscfp; ngx_http_core_srv_conf_t *cscf, **cscfp;
ngx_http_core_main_conf_t *cmcf;
ngx_test_null(ctx, if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), return NGX_CONF_ERROR;
NGX_CONF_ERROR); }
http_ctx = cf->ctx; http_ctx = cf->ctx;
ctx->main_conf = http_ctx->main_conf; ctx->main_conf = http_ctx->main_conf;
/* the server{}'s srv_conf */ /* the server{}'s srv_conf */
ngx_test_null(ctx->srv_conf, ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), if (ctx->srv_conf == NULL) {
NGX_CONF_ERROR); return NGX_CONF_ERROR;
}
/* the server{}'s loc_conf */ /* the server{}'s loc_conf */
ngx_test_null(ctx->loc_conf, ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), if (ctx->loc_conf == NULL) {
NGX_CONF_ERROR); return NGX_CONF_ERROR;
}
for (m = 0; ngx_modules[m]; m++) { for (m = 0; ngx_modules[m]; m++) {
if (ngx_modules[m]->type != NGX_HTTP_MODULE) { 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; module = ngx_modules[m]->ctx;
if (module->create_srv_conf) { if (module->create_srv_conf) {
ngx_test_null(ctx->srv_conf[ngx_modules[m]->ctx_index], if (!(mconf = module->create_srv_conf(cf))) {
module->create_srv_conf(cf), return NGX_CONF_ERROR;
NGX_CONF_ERROR); }
ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf;
} }
if (module->create_loc_conf) { if (module->create_loc_conf) {
ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index], if (!(mconf = module->create_loc_conf(cf))) {
module->create_loc_conf(cf), return NGX_CONF_ERROR;
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->srv_conf[ngx_http_core_module.ctx_index];
cscf->ctx = ctx; cscf->ctx = ctx;
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; 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; *cscfp = cscf;
/* parse inside server{} */ /* parse inside server{} */
save = *cf; 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, static char *
void *dummy) ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
{ {
char *rv; char *rv;
ngx_int_t m; 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) { if (pclcf->name.len == 0) {
cscf = ctx->srv_conf[ngx_http_core_module.ctx_index]; 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; 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_int_t rc;
ngx_http_core_loc_conf_t *first, *second; 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; char *rv;
ngx_conf_t save; 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, static char *
void *conf) ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
{ {
ngx_http_core_loc_conf_t *lcf = 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; 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; 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_http_core_srv_conf_t *cscf;
ngx_test_null(cscf, if (!(cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)))) {
ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)), return NGX_CONF_ERROR;
NGX_CONF_ERROR); }
/* /*
*
* set by ngx_pcalloc(): * set by ngx_pcalloc():
*
* conf->client_large_buffers.num = 0; * conf->client_large_buffers.num = 0;
*/ */
ngx_init_array(cscf->locations, cf->pool, if (ngx_array_init(&cscf->locations, cf->pool, 5, sizeof(void *))
5, sizeof(void *), NGX_CONF_ERROR); == NGX_ERROR)
ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t), {
NGX_CONF_ERROR); return 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->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->connection_pool_size = NGX_CONF_UNSET_SIZE;
cscf->post_accept_timeout = NGX_CONF_UNSET_MSEC; 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, static char *
void *parent, void *child) 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 *prev = parent;
ngx_http_core_srv_conf_t *conf = child; ngx_http_core_srv_conf_t *conf = child;
ngx_http_listen_t *l; ngx_http_listen_t *ls;
ngx_http_server_name_t *n; ngx_http_server_name_t *sn;
ngx_http_core_main_conf_t *cmcf; ngx_http_core_main_conf_t *cmcf;
/* TODO: it does not merge, it inits only */ /* TODO: it does not merge, it inits only */
if (conf->listen.nelts == 0) { if (conf->listen.nelts == 0) {
ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR); if (!(ls = ngx_array_push(&conf->listen))) {
l->addr = INADDR_ANY; return NGX_CONF_ERROR;
}
ls->addr = INADDR_ANY;
#if (NGX_WIN32) #if (NGX_WIN32)
l->port = 80; ls->port = 80;
#else #else
/* STUB: getuid() should be cached */ /* STUB: getuid() should be cached */
l->port = (getuid() == 0) ? 80 : 8000; ls->port = (getuid() == 0) ? 80 : 8000;
#endif #endif
l->family = AF_INET; ls->family = AF_INET;
} }
if (conf->server_names.nelts == 0) { if (conf->server_names.nelts == 0) {
ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR); if (!(sn = ngx_array_push(&conf->server_names))) {
ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN), return NGX_CONF_ERROR;
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, ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
"gethostname() failed"); "gethostname() failed");
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
n->name.len = ngx_strlen(n->name.data); sn->name.len = ngx_strlen(sn->name.data);
n->core_srv_conf = conf; sn->core_srv_conf = conf;
n->wildcard = 0; sn->wildcard = 0;
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
if (cmcf->max_server_name_len < n->name.len) { if (cmcf->max_server_name_len < sn->name.len) {
cmcf->max_server_name_len = n->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, ngx_conf_merge_unsigned_value(conf->restrict_host_names,
prev->restrict_host_names, 0); prev->restrict_host_names, 0);
return NGX_CONF_OK; 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_http_core_loc_conf_t *lcf;
ngx_test_null(lcf, if (!(lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)))) {
ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)), return NGX_CONF_ERROR;
NGX_CONF_ERROR); }
/* /*
* set by ngx_pcalloc(): * 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("html"), ngx_string("text/html") },
{ ngx_string("gif"), ngx_string("image/gif") }, { ngx_string("gif"), ngx_string("image/gif") },
{ ngx_string("jpg"), ngx_string("image/jpeg") }, { 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) void *parent, void *child)
{ {
ngx_http_core_loc_conf_t *prev = parent; ngx_http_core_loc_conf_t *prev = parent;
ngx_http_core_loc_conf_t *conf = child; ngx_http_core_loc_conf_t *conf = child;
int i, key; uint32_t key;
ngx_http_type_t *t; ngx_uint_t i;
ngx_http_type_t *type;
ngx_conf_merge_str_value(conf->root, prev->root, "html"); 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; conf->types = prev->types;
} else { } else {
ngx_test_null(conf->types, conf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME
ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME * sizeof(ngx_array_t));
* sizeof(ngx_array_t)), if (conf->types == NULL) {
NGX_CONF_ERROR); 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);
} }
for (i = 0; default_types[i].exten.len; i++) { for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) {
ngx_http_types_hash_key(key, default_types[i].exten); if (ngx_array_init(&conf->types[i], cf->pool, 5,
sizeof(ngx_http_type_t)) == NGX_ERROR)
{
return NGX_CONF_ERROR;
}
}
ngx_test_null(t, ngx_push_array(&conf->types[key]), for (i = 0; ngx_http_core_default_types[i].exten.len; i++) {
NGX_CONF_ERROR); ngx_http_types_hash_key(key,
t->exten.len = default_types[i].exten.len; ngx_http_core_default_types[i].exten);
t->exten.data = default_types[i].exten.data;
t->type.len = default_types[i].type.len; if (!(type = ngx_array_push(&conf->types[key]))) {
t->type.data = default_types[i].type.data; 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, 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, ngx_conf_merge_size_value(conf->client_max_body_size,
prev->client_max_body_size, 1 * 1024 * 1024); 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_garbage_collector_temp_handler, cf);
ngx_conf_merge_value(conf->reset_timedout_connection, 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); ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
if (conf->open_files == NULL) { 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, static char *
void *conf) ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_http_core_srv_conf_t *scf = 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); ls->addr = inet_addr((const char *) addr);
if (ls->addr == INADDR_NONE) { if (ls->addr == INADDR_NONE) {
h = gethostbyname((const char *) addr); 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, static char *
void *conf) ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_http_core_srv_conf_t *scf = 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; 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, static char *
void *conf) ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_http_core_loc_conf_t *lcf = conf; ngx_http_core_loc_conf_t *lcf = conf;
int overwrite; ngx_int_t overwrite;
ngx_uint_t i, n; ngx_uint_t i, n;
ngx_str_t *value; ngx_str_t *value;
ngx_http_err_page_t *err; ngx_http_err_page_t *err;
if (lcf->error_pages == NULL) { 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)); sizeof(ngx_http_err_page_t));
if (lcf->error_pages == NULL) { if (lcf->error_pages == NULL) {
return NGX_CONF_ERROR; 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++) { 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; return NGX_CONF_ERROR;
} }
err->status = ngx_atoi(value[i].data, value[i].len); err->status = ngx_atoi(value[i].data, value[i].len);
if (err->status == NGX_ERROR) { if (err->status == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid value \"%V\"", &value[i]); "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, static char *
void *conf) ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_http_core_loc_conf_t *lcf = 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; value = cf->args->elts;
lcf->keepalive_timeout = ngx_parse_time(&value[1], 0); lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) { if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
return "invalid value"; 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); lcf->keepalive_header = ngx_parse_time(&value[2], 1);
if (lcf->keepalive_header == NGX_ERROR) { if (lcf->keepalive_header == NGX_ERROR) {
return "invalid value"; 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, static char *
void *conf) ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_http_core_loc_conf_t *lcf = 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) #if (NGX_FREEBSD)
ssize_t *np = data; ssize_t *np = data;

View File

@ -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;
} }

View File

@ -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_int_t rc;
ngx_uint_t err, i, msie_padding; ngx_uint_t err, i, msie_padding;

View File

@ -12,29 +12,26 @@
static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev); static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev);
static void ngx_http_upstream_connect(ngx_http_request_t *r, 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, 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, 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_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);
static void ngx_http_upstream_send_response(ngx_http_request_t *r, 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_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);
static void ngx_http_upstream_next(ngx_http_request_t *r, static void ngx_http_upstream_next(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_http_upstream_t *u, ngx_uint_t ft_type);
ngx_uint_t ft_type);
static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_http_upstream_t *u, ngx_int_t rc);
ngx_int_t rc);
static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r,
uintptr_t data); uintptr_t data);
static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r,
ngx_http_log_op_t *op); u_char *buf, ngx_http_log_op_t *op);
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);
@ -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_connection_t *c;
ngx_http_upstream_t *u; 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; int n;
char buf[1]; 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, static void
ngx_http_upstream_t *u) ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
{ {
ngx_int_t rc; ngx_int_t rc;
ngx_connection_t *c; 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, static void
ngx_http_upstream_t *u) ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
{ {
ngx_chain_t *cl; 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)); 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, static void
ngx_http_upstream_t *u) ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u)
{ {
int rc; int rc;
ngx_connection_t *c; 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_connection_t *c;
ngx_http_request_t *r; 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; ssize_t n;
ngx_int_t rc; ngx_int_t rc;
ngx_connection_t *c; ngx_uint_t i;
ngx_http_request_t *r; ngx_connection_t *c;
ngx_http_upstream_t *u; 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; c = rev->data;
r = c->data; r = c->data;
@ -657,12 +658,31 @@ static void ngx_http_upstream_process_header(ngx_event_t *rev)
/* rc == NGX_OK */ /* 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); ngx_http_upstream_send_response(r, u);
} }
static void ngx_http_upstream_send_response(ngx_http_request_t *r, static void
ngx_http_upstream_t *u) ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
{ {
ngx_int_t rc; ngx_int_t rc;
ngx_event_pipe_t *p; 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_connection_t *c;
ngx_http_request_t *r; 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, ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
"http upstream dummy handler"); "http upstream dummy handler");
} }
static void ngx_http_upstream_next(ngx_http_request_t *r, static void
ngx_http_upstream_t *u, ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
ngx_uint_t ft_type) ngx_uint_t ft_type)
{ {
ngx_uint_t status; 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, static void
ngx_http_upstream_t *u, ngx_http_upstream_finalize_request(ngx_http_request_t *r,
ngx_int_t rc) ngx_http_upstream_t *u, ngx_int_t rc)
{ {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http upstream request: %i", rc); "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, static size_t
uintptr_t data) ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, uintptr_t data)
{ {
if (r->upstream) { if (r->upstream) {
return r->upstream->states.nelts * (3 + 2); 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, static u_char *
ngx_http_log_op_t *op) ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op)
{ {
ngx_uint_t i; ngx_uint_t i;
ngx_http_upstream_t *u; 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; u_char *p;
ngx_int_t escape; 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; ngx_http_log_op_name_t *op;

View File

@ -54,6 +54,7 @@ typedef struct {
ngx_bufs_t bufs; ngx_bufs_t bufs;
ngx_flag_t redirect_errors;
ngx_flag_t x_powered_by; ngx_flag_t x_powered_by;
ngx_flag_t cyclic_temp_file; ngx_flag_t cyclic_temp_file;
@ -95,13 +96,6 @@ struct ngx_http_upstream_s {
ngx_http_log_ctx_t *saved_log_ctx; ngx_http_log_ctx_t *saved_log_ctx;
ngx_log_handler_pt saved_log_handler; 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_http_upstream_state_t *state;
ngx_array_t states; /* of ngx_http_upstream_state_t */ ngx_array_t states; /* of ngx_http_upstream_state_t */