src/http/ngx_http_script.h \
src/http/ngx_http_upstream.h \
src/http/ngx_http_busy_lock.h \
- src/http/ngx_http_log_module.h"
+ src/http/modules/ngx_http_log_module.h"
HTTP_SRCS="src/http/ngx_http.c \
src/http/ngx_http_core_module.c \
src/http/ngx_http_header_filter_module.c \
src/http/ngx_http_write_filter_module.c \
src/http/ngx_http_copy_filter_module.c \
- src/http/ngx_http_log_module.c \
+ src/http/modules/ngx_http_log_module.c \
src/http/ngx_http_request_body.c \
src/http/ngx_http_variables.c \
src/http/ngx_http_script.c \
CORE_LIBS="$CORE_LIBS -pthread"
;;
- FreeBSD:5*)
+ FreeBSD:[567]*)
have=NGX_THREADS . auto/have
CORE_SRCS="$CORE_SRCS $PTHREAD_SRCS"
CORE_LIBS="$CORE_LIBS -lc_r"
index index.html index.htm;
}
+ # proxy the PHP scripts to Apache listening on 127.0.0.1:80
+ #
+ #location ~ \.php$ {
+ # proxy_pass http://127.0.0.1;
+ #}
+
# deny access to .htaccess files
#
#location ~ /\.ht {
<title lang="en">nginx changelog</title>
+<changes ver="0.3.6" date="24.10.2005">
+
+<change type="change">
+<para lang="ru">
+IMAP/POP3 ÐÒÏËÓÉ ÔÅÐÅÒØ ÎÅ ÐÅÒÅÄÁ£Ô ÓÅÒ×ÅÒÕ Á×ÔÏÒÉÚÁÃÉÉ ÐÕÓÔÏÊ ÌÏÇÉÎ.
+</para>
+<para lang="en">
+now the IMAP/POP3 proxy do not send the empty login to authorization server.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+ÄÉÒÅËÔÉ×Á log_format ÐÏÄÄÅÒÖÉ×ÁÅÔ ÐÅÒÅÍÅÎÎÙÅ × ×ÉÄÅ $name.
+</para>
+<para lang="en">
+the "log_format" supports the variables in the $name form.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+ÅÓÌÉ ÈÏÔÑ ÂÙ × ÏÄÎÏÍ ÓÅÒ×ÅÒÅ ÎÅ ÂÙÌÏ ÏÐÉÓÁÎÏ ÎÉ ÏÄÎÏÊ ÄÉÒÅËÔÉ×Ù listen, ÔÏ
+nginx ÎÅ ÓÌÕÛÁÌ ÎÁ 80 ÐÏÒÔÕ;
+ÏÛÉÂËÁ ÐÏÑ×ÉÌÁÓØ × 0.3.3.
+</para>
+<para lang="en">
+if at least in one server was no the "listen" directive, then nginx did not
+listen on the 80 port;
+bug appeared in 0.3.3.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+ÅÓÌÉ × ÄÉÒÅËÔÉ×Å proxy_pass ÏÔÓÕÔÓÔ×Ï×ÁÌ URI, ÔÏ ×ÓÅÇÄÁ ÉÓÐÏÌØÚÏ×ÁÌÓÑ ÐÏÒÔ 80.
+</para>
+<para lang="en">
+if the URI part is omitted in "proxy_pass" directive, the the 80 port was
+always used.
+</para>
+</change>
+
+</changes>
+
+
<changes ver="0.3.5" date="21.10.2005">
<change type="bugfix">
<change type="feature">
<para lang="ru">
-ËÏÍÁÎÄÁ config errmsg × ÍÏÄÕÌÅ ngx_http_sssi_module.
+ËÏÍÁÎÄÁ config errmsg × ÍÏÄÕÌÅ ngx_http_ssi_module.
</para>
<para lang="en">
the "config errmsg" command of the ngx_http_ssi_module.
#define _NGINX_H_INCLUDED_
-#define NGINX_VER "nginx/0.3.5"
+#define NGINX_VER "nginx/0.3.6"
#define NGINX_VAR "NGINX"
#define NGX_OLDPID_EXT ".oldbin"
== -1)
{
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
- "setsockopt(SO_RCVBUF) %V failed, ignored",
- &ls[i].addr_text);
- return;
+ "setsockopt(SO_RCVBUF, %d) %V failed, ignored",
+ ls[i].rcvbuf, &ls[i].addr_text);
}
}
== -1)
{
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
- "setsockopt(SO_SNDBUF) %V failed, ignored",
- &ls[i].addr_text);
- return;
+ "setsockopt(SO_SNDBUF, %d) %V failed, ignored",
+ ls[i].sndbuf, &ls[i].addr_text);
}
}
}
}
- if (u->port_text.data == NULL) {
+ if (u->port_text.data) {
+
+ if (u->port_text.len == 0) {
+ u->port_text.len = &url->data[i] - u->port_text.data;
+
+ if (u->port_text.len == 0) {
+ return "invalid port";
+ }
+ }
+
+ port = ngx_atoi(u->port_text.data, u->port_text.len);
+
+ if (port == NGX_ERROR || port < 1 || port > 65536) {
+ return "invalid port";
+ }
+
+ } else {
port = ngx_atoi(url->data, url->len);
if (port == NGX_ERROR) {
u->port_text = *url;
u->wildcard = 1;
-
- } else {
- if (u->port_text.len == 0) {
- u->default_port = 1;
- return NULL;
- }
-
- port = ngx_atoi(u->port_text.data, u->port_text.len);
-
- if (port == NGX_ERROR || port < 1 || port > 65536) {
- return "invalid port";
- }
}
u->port = (in_port_t) port;
last = ctx->output_filter(ctx->filter_ctx, out);
- ngx_chain_update_chains(&ctx->free, &ctx->busy, &out, ctx->tag);
- last_out = &out;
-
- if (last == NGX_ERROR) {
+ if (last == NGX_ERROR || last == NGX_DONE) {
return last;
}
+
+ ngx_chain_update_chains(&ctx->free, &ctx->busy, &out, ctx->tag);
+ last_out = &out;
}
}
void *conf);
static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
+static ngx_int_t ngx_http_log_init(ngx_cycle_t *cycle);
static ngx_command_t ngx_http_log_commands[] = {
ngx_http_log_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
- NULL, /* init module */
+ ngx_http_log_init, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
static ngx_str_t ngx_http_combined_fmt =
- ngx_string("%addr - - [%time] \"%request\" %status %apache_length "
- "\"%{Referer}i\" \"%{User-Agent}i\"");
+#if 0
+ ngx_string("$remote_addr - $remote_user [%time] "
+ "\"$request\" %status %apache_length "
+ "\"$http_referer\" \"$http_user_agent\"");
+#endif
+ ngx_string("%addr - - [%time] "
+ "\"%request\" %status %apache_length "
+ "\"%{referer}i\" \"%{user-agent}i\"");
ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = {
}
if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t))
- == NGX_ERROR)
+ == NGX_ERROR)
{
return NGX_CONF_ERROR;
}
return NGX_CONF_ERROR;
}
+ value->len = 0;
+ value->data = NULL;
+
value = ngx_array_push(cf->args);
if (value == NULL) {
return NGX_CONF_ERROR;
rc = ngx_http_log_set_format(cf, NULL, conf);
if (rc != NGX_CONF_OK) {
- return NULL;
+ return NGX_CONF_ERROR;
}
return conf;
{
ngx_http_log_main_conf_t *lmcf = conf;
- ngx_uint_t s, f, invalid;
- u_char *data, *p, *fname;
+ u_char *data, *p, *fname, ch;
size_t i, len, fname_len;
- ngx_str_t *value, arg, *a;
+ ngx_str_t *value, var, arg, *a;
+ ngx_uint_t s, f, bracket;
ngx_http_log_op_t *op;
ngx_http_log_fmt_t *fmt;
ngx_http_log_op_name_t *name;
return NGX_CONF_ERROR;
}
- invalid = 0;
- data = NULL;
arg.data = NULL;
- for (s = 2; s < cf->args->nelts && !invalid; s++) {
+ for (s = 2; s < cf->args->nelts; s++) {
i = 0;
i++;
if (i == value[s].len) {
- invalid = 1;
- break;
+ goto invalid;
}
if (value[s].data[i] == '{') {
arg.len = &value[s].data[i] - arg.data;
if (i == value[s].len || arg.len == 0) {
- invalid = 1;
- break;
+ goto invalid;
}
i++;
fname_len = &value[s].data[i] - fname;
if (fname_len == 0) {
- invalid = 1;
- break;
+ goto invalid;
}
for (name = ngx_http_log_fmt_ops; name->run; name++) {
}
if (name->name.len == 0) {
- invalid = 1;
+ goto invalid;
+ }
+
+ } else if (value[s].data[i] == '$') {
+
+ if (++i == value[s].len) {
+ goto invalid;
+ }
+
+ if (value[s].data[i] == '{') {
+ bracket = 1;
+
+ if (++i == value[s].len) {
+ goto invalid;
+ }
+
+ var.data = &value[s].data[i];
+
+ } else {
+ bracket = 0;
+ var.data = &value[s].data[i];
+ }
+
+ for (var.len = 0; i < value[s].len; i++, var.len++) {
+ ch = value[s].data[i];
+
+ if (ch == '}' && bracket) {
+ i++;
+ bracket = 0;
+ break;
+ }
+
+ if ((ch >= 'A' && ch <= 'Z')
+ || (ch >= 'a' && ch <= 'z')
+ || (ch >= '0' && ch <= '9')
+ || ch == '_')
+ {
+ continue;
+ }
+
break;
}
+ if (bracket) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "the closing bracket in \"%V\" "
+ "variable is missing", &var);
+ return NGX_CONF_ERROR;
+ }
+
+ if (var.len == 0) {
+ goto invalid;
+ }
+
+ if (ngx_http_log_variable_compile(cf, op, &var) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
+
} else {
i++;
- while (i < value[s].len && value[s].data[i] != '%') {
+ while (i < value[s].len
+ && value[s].data[i] != '$'
+ && value[s].data[i] != '%')
+ {
i++;
}
}
}
- if (invalid) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid parameter \"%s\"", data);
- return NGX_CONF_ERROR;
- }
-
return NGX_CONF_OK;
+
+invalid:
+
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%s\"", data);
+
+ return NGX_CONF_ERROR;
+}
+
+
+static ngx_int_t
+ngx_http_log_init(ngx_cycle_t *cycle)
+{
+ ngx_http_core_main_conf_t *cmcf;
+
+ cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+
+ cmcf->log_handler = ngx_http_log_handler;
+
+ return NGX_OK;
}
};
-static ngx_int_t (*ngx_http_next_header_filter) (ngx_http_request_t *r);
-static ngx_int_t (*ngx_http_next_body_filter) (ngx_http_request_t *r,
- ngx_chain_t *in);
+static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
+static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static u_char ngx_http_ssi_string[] = "<!--";
ngx_buf_t *b;
ngx_chain_t *cl;
ngx_table_elt_t *param;
+ ngx_connection_t *c;
ngx_http_ssi_ctx_t *ctx;
ngx_http_ssi_conf_t *conf;
ngx_http_ssi_param_t *prm;
}
}
- if (cmd->handler(r, ctx, params) == NGX_OK) {
+ c = r->connection;
+
+ rc = cmd->handler(r, ctx, params);
+
+ if (c->closed) {
+ return NGX_DONE;
+ }
+
+ if (rc == NGX_OK) {
continue;
}
}
static ngx_int_t
ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
- ngx_int_t rc;
ngx_output_chain_ctx_t *ctx;
ngx_http_copy_filter_conf_t *conf;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"copy filter: \"%V\"", &r->uri);
- if (r->connection->closed) {
- rc = ngx_http_next_filter(r, in);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "copy closed filter: %i \"%V\"", rc, &r->uri);
- return rc;
- }
-
ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module);
if (ctx == NULL) {
}
- rc = ngx_output_chain(ctx, in);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "copy filter: %i \"%V\"", rc, &r->uri);
+ /* the request pool may be already destroyed after ngx_output_chain()*/
- return rc;
+ return ngx_output_chain(ctx, in);
}
ngx_http_handler(sr);
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http subrequest \"%V\" done", uri);
+ /* the request pool may be already destroyed */
return NGX_OK;
}
}
-#if 0 /* STUB: test the delay http handler */
-
-ngx_int_t
-ngx_http_delay_handler(ngx_http_request_t *r)
+ngx_http_cleanup_t *
+ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
{
- static int on;
+ ngx_http_cleanup_t *cln;
- if (on++ == 0) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http set delay");
- ngx_add_timer(r->connection->write, 10000);
- return NGX_AGAIN;
+ r = r->main;
+
+ cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
+ if (cln == NULL) {
+ return NULL;
}
- r->connection->write->timedout = 0;
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http reset delay");
- return NGX_DECLINED;
-}
+ if (size) {
+ cln->data = ngx_palloc(r->pool, size);
+ if (cln->data == NULL) {
+ return NULL;
+ }
-#endif
+ } else {
+ cln->data = NULL;
+ }
+
+ cln->handler = NULL;
+ cln->next = r->cleanup;
+
+ r->cleanup = cln;
+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "http cleanup add: %p", cln);
+
+ return cln;
+}
static char *
}
if (ngx_array_init(&cmcf->servers, cf->pool, 4,
- sizeof(ngx_http_core_srv_conf_t *)) == NGX_ERROR)
+ sizeof(ngx_http_core_srv_conf_t *))
+ == NGX_ERROR)
{
return NGX_CONF_ERROR;
}
ls->port = (getuid() == 0) ? 80 : 8000;
#endif
ls->family = AF_INET;
+
+ ls->conf.backlog = -1;
+ ls->conf.rcvbuf = -1;
+ ls->conf.sndbuf = -1;
}
if (conf->server_names.nelts == 0) {
ngx_array_t servers; /* ngx_http_core_srv_conf_t */
ngx_http_phase_t phases[NGX_HTTP_LAST_PHASE];
- ngx_array_t index_handlers;
+ ngx_http_handler_pt log_handler;
ngx_hash_t headers_in_hash;
ngx_hash_t variables_hash;
ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
ngx_str_t *uri, ngx_str_t *args);
+ngx_http_cleanup_t *ngx_http_cleanup_add(ngx_http_request_t *r, size_t size);
+
typedef ngx_int_t (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
typedef ngx_int_t (*ngx_http_output_body_filter_pt)
};
-ngx_http_header0_t ngx_http_headers_out[] = {
+ngx_http_header_out_t ngx_http_headers_out[] = {
{ ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) },
{ ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) },
#if 0
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http postpone filter \"%V\" %p", &r->uri, in);
- if (r->connection->closed) {
-
- if (r->postponed) {
- r->postponed = r->postponed->next;
- }
-
- return NGX_ERROR;
- }
-
if (r != r->connection->data || (r->postponed && in)) {
if (r->postponed) {
static void ngx_http_set_lingering_close(ngx_http_request_t *r);
static void ngx_http_lingering_close_handler(ngx_event_t *ev);
static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error);
+static void ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error);
static void ngx_http_close_connection(ngx_connection_t *c);
static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len);
rev = c->read;
rev->handler = ngx_http_init_request;
-
- /* STUB: epoll edge */ c->write->handler = ngx_http_empty_handler;
+ c->write->handler = ngx_http_empty_handler;
#if (NGX_STAT_STUB)
ngx_atomic_fetch_add(ngx_stat_reading, 1);
sizeof(ngx_table_elt_t)) == NGX_ERROR)
{
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
return;
}
r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
if (r->ctx == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
return;
}
ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
c->timedout = 1;
ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT);
- ngx_http_close_connection(c);
return;
}
r = c->data;
ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST);
- ngx_http_close_connection(r->connection);
return;
}
ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
c->timedout = 1;
ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT);
- ngx_http_close_connection(c);
return;
}
r->uri.data = ngx_palloc(r->pool, r->uri.len + 1);
if (r->uri.data == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
return;
}
sizeof(ngx_table_elt_t)) == NGX_ERROR)
{
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
return;
}
sizeof(ngx_table_elt_t *)) == NGX_ERROR)
{
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
return;
}
if (rv == NGX_ERROR) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
return;
}
ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
c->timedout = 1;
ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT);
- ngx_http_close_connection(c);
return;
}
if (rv == NGX_ERROR) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
return;
}
"client sent too long header line: \"%V\"",
&header);
ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST);
- ngx_http_close_connection(c);
return;
}
}
h = ngx_list_push(&r->headers_in.headers);
if (h == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
return;
}
"client sent invalid header line: \"%V\\r...\"",
&header);
ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST);
- ngx_http_close_connection(c);
return;
}
}
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(r->connection);
return NGX_ERROR;
}
if (n == 0 || n == NGX_ERROR) {
ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST);
- ngx_http_close_connection(r->connection);
return NGX_ERROR;
}
}
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(r->connection);
return NGX_ERROR;
}
if (cscf->restrict_host_names == NGX_HTTP_RESTRICT_HOST_CLOSE) {
ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST);
- ngx_http_close_connection(r->connection);
return NGX_ERROR;
}
ngx_http_core_loc_conf_t *clcf;
if (rc == NGX_DONE) {
- /* r may be already destroyed when rc == NGX_DONE */
+ /* the request pool may be already destroyed */
return;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http finalize request: %d, \"%V\"", rc, &r->uri);
- if (r->parent
- && (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT))
- {
+ if (rc == NGX_ERROR || r->connection->closed) {
+ ngx_http_close_request(r, 0);
+ return;
+ }
+
+ if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT) {
+
+ if (r->main == r) {
+ if (r->connection->read->timer_set) {
+ ngx_del_timer(r->connection->read);
+ }
+
+ if (r->connection->write->timer_set) {
+ ngx_del_timer(r->connection->write);
+ }
+ }
+
ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));
+
return;
}
- if (r->parent || rc == NGX_AGAIN) {
+ if (r->main != r || rc == NGX_AGAIN) {
if (ngx_http_set_write_handler(r) != NGX_OK) {
return;
}
return;
}
- if (r->parent) {
+ if (r->main != r) {
pr = r->parent;
return;
}
- if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT) {
-
- if (r->connection->read->timer_set) {
- ngx_del_timer(r->connection->read);
- }
-
- if (r->connection->write->timer_set) {
- ngx_del_timer(r->connection->write);
- }
-
- if (r->connection->closed) {
- ngx_http_close_request(r, 0);
- ngx_http_close_connection(r->connection);
- return;
- }
-
- ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));
-
- return;
- }
-
- if (rc == NGX_ERROR || r->connection->closed) {
- ngx_http_close_request(r, 0);
- ngx_http_close_connection(r->connection);
+ if (rc == NGX_AGAIN) {
return;
}
- if (rc == NGX_AGAIN || r->out) {
+ if (r->out) {
(void) ngx_http_set_write_handler(r);
return;
}
"kevent() reported about an closed connection");
#endif
ngx_http_close_request(r, 0);
- ngx_http_close_connection(r->connection);
return;
}
}
ngx_http_close_request(r, 0);
- ngx_http_close_connection(r->connection);
}
r->write_event_handler = ngx_http_writer;
- if (r->connection->closed) {
- return NGX_OK;
- }
-
wev = r->connection->write;
if (wev->ready && wev->delayed) {
if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) {
ngx_http_close_request(r, 0);
- ngx_http_close_connection(r->connection);
return NGX_ERROR;
}
"client timed out");
c->timedout = 1;
-#if 0
- ngx_http_close_request(r->main, NGX_HTTP_REQUEST_TIME_OUT);
- ngx_http_close_connection(c);
-#endif
-
- c->closed = 1;
- ngx_http_finalize_request(r, 0);
-
+ ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT);
return;
}
ngx_add_timer(wev, clcf->send_timeout);
if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) {
- ngx_http_close_request(r->main, 0);
- ngx_http_close_connection(r->connection);
+ ngx_http_close_request(r, 0);
}
return;
clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module);
if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) {
- ngx_http_close_request(r->main, 0);
- ngx_http_close_connection(r->connection);
+ ngx_http_close_request(r, 0);
}
return;
rc = ngx_http_postponed_handler(r);
if (rc == NGX_DONE) {
- /* r may be already destroyed when rc == NGX_DONE */
+ /* the request pool may be already destroyed */
return;
}
}
if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) {
- ngx_http_close_request(r->main, 0);
- ngx_http_close_connection(r->connection);
+ ngx_http_close_request(r, 0);
}
return;
rc = ngx_http_output_filter(r, NULL);
+ if (rc == NGX_DONE) {
+ /* the request pool is already destroyed */
+ return NGX_DONE;
+ }
+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http postponed output filter: %d", rc);
- /*
- * we treat NGX_ERROR as NGX_OK, because we need to complete
- * all postponed requests
- */
+ if (rc == NGX_ERROR) {
+ ngx_http_close_request(r, 0);
+ return NGX_DONE;
+ }
pr = r->postponed;
== NGX_ERROR)
{
ngx_http_close_request(r, 0);
- ngx_http_close_connection(r->connection);
}
}
}
if (rc == NGX_AGAIN) {
if (ngx_handle_read_event(r->connection->read, 0) == NGX_ERROR) {
ngx_http_close_request(r, rc);
- ngx_http_close_connection(r->connection);
return;
}
}
if (rc != NGX_OK) {
ngx_http_close_request(r, rc);
- ngx_http_close_connection(r->connection);
}
}
if (hc->free == NULL) {
ngx_http_close_request(r, 0);
- ngx_http_close_connection(c);
return;
}
}
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
- ngx_http_close_request(r, 0);
+ ngx_http_request_done(r, 0);
+
c->data = hc;
ngx_add_timer(rev, clcf->keepalive_timeout);
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_close_request(r, 0);
- ngx_http_close_connection(c);
return;
}
== NGX_ERROR)
{
ngx_http_close_request(r, 0);
- ngx_http_close_connection(c);
return;
}
} else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) {
if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) {
ngx_http_close_request(r, 0);
- ngx_http_close_connection(c);
return;
}
}
ngx_connection_error(c, ngx_socket_errno,
ngx_shutdown_socket_n " failed");
ngx_http_close_request(r, 0);
- ngx_http_close_connection(c);
return;
}
if (rev->timedout) {
ngx_http_close_request(r, 0);
- ngx_http_close_connection(c);
return;
}
timer = r->lingering_time - ngx_time();
if (timer <= 0) {
ngx_http_close_request(r, 0);
- ngx_http_close_connection(c);
return;
}
if (n == NGX_ERROR || n == 0) {
ngx_http_close_request(r, 0);
- ngx_http_close_connection(c);
return;
}
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_close_request(r, 0);
- ngx_http_close_connection(c);
return;
}
void
ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error)
{
- ngx_log_t *log;
- struct linger linger;
- ngx_http_log_ctx_t *ctx;
- ngx_http_core_loc_conf_t *clcf;
+ ngx_connection_t *c;
+ ngx_http_cleanup_t *cln;
+
+ c = r->connection;
+ r = r->main;
+
+ for (cln = r->cleanup; cln; cln = cln->next) {
+ if (cln->handler) {
+ cln->handler(cln->data);
+ }
+ }
+
+ ngx_http_request_done(r, error);
+ ngx_http_close_connection(c);
+}
+
+
+void
+ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error)
+{
+ ngx_log_t *log;
+ struct linger linger;
+ ngx_http_log_ctx_t *ctx;
+ ngx_http_core_loc_conf_t *clcf;
+ ngx_http_core_main_conf_t *cmcf;
log = r->connection->log;
r->headers_out.status = error;
}
- ngx_http_log_handler(r);
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+ if (cmcf->log_handler) {
+ cmcf->log_handler(r);
+ }
if (r->connection->timedout) {
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
typedef struct {
ngx_str_t name;
ngx_uint_t offset;
-} ngx_http_header0_t;
+} ngx_http_header_out_t;
typedef struct {
} ngx_http_connection_t;
+typedef void (*ngx_http_cleanup_pt)(void *data);
+
+typedef struct ngx_http_cleanup_s ngx_http_cleanup_t;
+
+struct ngx_http_cleanup_s {
+ ngx_http_cleanup_pt handler;
+ void *data;
+ ngx_http_cleanup_t *next;
+};
+
+
typedef struct ngx_http_postponed_request_s ngx_http_postponed_request_t;
struct ngx_http_postponed_request_s {
ngx_http_log_handler_pt log_handler;
+ ngx_http_cleanup_t *cleanup;
+
unsigned http_state:4;
/* URI with "/." and on Win32 with "//" */
};
-extern ngx_http_header_t ngx_http_headers_in[];
-extern ngx_http_header0_t ngx_http_headers_out[];
+extern ngx_http_header_t ngx_http_headers_in[];
+extern ngx_http_header_out_t ngx_http_headers_out[];
#endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */
static void ngx_http_upstream_dummy_handler(ngx_event_t *wev);
static void ngx_http_upstream_next(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_uint_t ft_type);
+static void ngx_http_upstream_cleanup(void *data);
static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_int_t rc);
{
ngx_time_t *tp;
ngx_connection_t *c;
+ ngx_http_cleanup_t *cln;
ngx_http_upstream_t *u;
ngx_http_core_loc_conf_t *clcf;
u->writer.pool = r->pool;
if (ngx_array_init(&u->states, r->pool, u->peer.peers->number,
- sizeof(ngx_http_upstream_state_t)) != NGX_OK)
+ sizeof(ngx_http_upstream_state_t))
+ != NGX_OK)
{
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
u->state->response_time = tp->sec * 1000 + tp->msec;
+ cln = ngx_http_cleanup_add(r, sizeof(void *));
+ if (cln == NULL) {
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ cln->handler = ngx_http_upstream_cleanup;
+ cln->data = r;
+ u->cleanup = &cln->handler;
+
ngx_http_upstream_connect(r, u);
}
}
}
- if (r->connection->write->eof) {
- r->connection->closed = 1;
+ if (r->connection->closed) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_CLIENT_CLOSED_REQUEST);
return;
}
+static void
+ngx_http_upstream_cleanup(void *data)
+{
+ ngx_http_request_t *r = data;
+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "cleanup http upstream request: \"%V\"", &r->uri);
+
+ ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE);
+}
+
+
static void
ngx_http_upstream_finalize_request(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_int_t rc)
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http upstream request: %i", rc);
+ *u->cleanup = NULL;
+
if (u->state->response_time) {
tp = ngx_timeofday();
u->state->response_time = tp->sec * 1000 + tp->msec
p = ngx_snprintf(buf, len,
", server: %V, URL: \"%V\","
- " upstream: %V%V%s%V",
+ " upstream: \"%V%V%s%V\"",
&r->server_name,
&r->unparsed_uri,
&u->conf->schema,
ngx_str_t uri;
+ ngx_http_cleanup_pt *cleanup;
+
unsigned cachable:1;
unsigned accel:1;
{ ngx_string("document_uri"), ngx_http_variable_request,
offsetof(ngx_http_request_t, uri), 0, 0 },
+ { ngx_string("request"), ngx_http_variable_request,
+ offsetof(ngx_http_request_t, request_line), 0, 0 },
+
{ ngx_string("document_root"), ngx_http_variable_document_root, 0, 0, 0 },
{ ngx_string("query_string"), ngx_http_variable_request,
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
if (ngx_array_init(&cmcf->all_variables, cf->pool, 32,
- sizeof(ngx_http_variable_t)) == NGX_ERROR)
+ sizeof(ngx_http_variable_t))
+ == NGX_ERROR)
{
return NGX_ERROR;
}
switch (s->command) {
case NGX_IMAP_LOGIN:
- if (s->args.nelts == 2) {
+ arg = s->args.elts;
- arg = s->args.elts;
+ if (s->args.nelts == 2 && arg[0].len) {
s->login.len = arg[0].len;
s->login.data = ngx_palloc(c->pool, s->login.len);