nginx-0.0.12-2004-09-23-20:39:34 import

This commit is contained in:
Igor Sysoev 2004-09-23 16:39:34 +00:00
parent f7abd72716
commit 236e045751
7 changed files with 176 additions and 64 deletions

View File

@ -2,7 +2,7 @@
#define _NGINX_H_INCLUDED_
#define NGINX_VER "nginx/0.0.11"
#define NGINX_VER "nginx/0.0.12"
#define NGINX_VAR "NGINX"
#define NGX_NEWPID_EXT ".newbin"

View File

@ -37,14 +37,24 @@ typedef struct {
} ngx_http_rewrite_srv_conf_t;
typedef struct {
ngx_str_t redirect;
} ngx_http_rewrite_loc_conf_t;
static void *ngx_http_rewrite_create_srv_conf(ngx_conf_t *cf);
static char *ngx_http_rewrite_merge_srv_conf(ngx_conf_t *cf,
void *parent, void *child);
static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_redirect(ngx_conf_t *cf, void *post, void *data);
static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle);
static ngx_conf_post_handler_pt ngx_http_redirect_p = ngx_http_redirect;
static ngx_command_t ngx_http_rewrite_commands[] = {
{ ngx_string("rewrite"),
@ -54,6 +64,13 @@ static ngx_command_t ngx_http_rewrite_commands[] = {
0,
NULL },
{ ngx_string("redirect"),
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
0,
&ngx_http_redirect_p },
{ ngx_string("rewrite_log"),
NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
@ -74,7 +91,7 @@ ngx_http_module_t ngx_http_rewrite_module_ctx = {
ngx_http_rewrite_create_srv_conf, /* create server configuration */
ngx_http_rewrite_merge_srv_conf, /* merge server configuration */
NULL, /* create location configration */
ngx_http_rewrite_create_loc_conf, /* create location configration */
NULL, /* merge location configration */
};
@ -203,6 +220,43 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
}
static ngx_int_t ngx_http_redirect_handler(ngx_http_request_t *r)
{
u_char *p;
ngx_http_rewrite_loc_conf_t *rlcf;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http redirect handler");
rlcf = ngx_http_get_module_loc_conf(r, ngx_http_rewrite_module);
r->headers_out.location = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (rlcf->redirect.data[0] != '/') {
r->headers_out.location->key.len = sizeof("Location") - 1;
r->headers_out.location->key.data = (u_char *) "Location";
}
r->headers_out.location->value.len = rlcf->redirect.len
+ r->unparsed_uri.len;
r->headers_out.location->value.data = ngx_palloc(r->pool,
r->headers_out.location->value.len);
if (r->headers_out.location->value.data == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
p = ngx_cpymem(r->headers_out.location->value.data, rlcf->redirect.data,
rlcf->redirect.len);
p = ngx_cpystrn(p, r->unparsed_uri.data + 1, r->unparsed_uri.len);
return NGX_HTTP_MOVED_TEMPORARILY;
}
static void *ngx_http_rewrite_create_srv_conf(ngx_conf_t *cf)
{
ngx_http_rewrite_srv_conf_t *conf;
@ -232,6 +286,18 @@ static char *ngx_http_rewrite_merge_srv_conf(ngx_conf_t *cf,
}
static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_rewrite_loc_conf_t *conf;
if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rewrite_loc_conf_t)))) {
return NGX_CONF_ERROR;
}
return conf;
}
static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
{
@ -366,6 +432,17 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
}
static char *ngx_http_redirect(ngx_conf_t *cf, void *post, void *data)
{
ngx_http_core_loc_conf_t *clcf;
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
clcf->handler = ngx_http_redirect_handler;
return NGX_CONF_OK;
}
static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle)
{
ngx_http_handler_pt *h;

View File

@ -401,7 +401,7 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev)
if (!p->cachable && p->upstream->peer.connection) {
ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
"kevent() reported that client have closed "
"kevent() reported that client closed "
"prematurely connection, "
"so upstream connection is closed too");
ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
@ -409,7 +409,7 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev)
}
ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
"kevent() reported that client have closed "
"kevent() reported that client closed "
"prematurely connection");
if (p->upstream == NULL || p->upstream->peer.connection == NULL) {
@ -464,14 +464,14 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev)
if (!p->cachable && p->upstream->peer.connection) {
ngx_log_error(NGX_LOG_INFO, ev->log, err,
"client have closed prematurely connection, "
"client closed prematurely connection, "
"so upstream connection is closed too");
ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
return;
}
ngx_log_error(NGX_LOG_INFO, ev->log, err,
"client have closed prematurely connection");
"client closed prematurely connection");
if (p->upstream == NULL || p->upstream->peer.connection == NULL) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);

View File

@ -234,13 +234,6 @@ static ngx_command_t ngx_http_core_commands[] = {
0,
NULL },
{ ngx_string("keepalive_buffers"),
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_core_loc_conf_t, keepalive_buffers),
NULL },
{ ngx_string("lingering_time"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
@ -1395,7 +1388,6 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf)
lcf->limit_rate = NGX_CONF_UNSET_SIZE;
lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
lcf->keepalive_header = NGX_CONF_UNSET;
lcf->keepalive_buffers = NGX_CONF_UNSET;
lcf->lingering_time = NGX_CONF_UNSET_MSEC;
lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
lcf->reset_timedout_connection = NGX_CONF_UNSET;
@ -1484,7 +1476,6 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
prev->keepalive_timeout, 75000);
ngx_conf_merge_sec_value(conf->keepalive_header,
prev->keepalive_header, 0);
ngx_conf_merge_value(conf->keepalive_buffers, prev->keepalive_buffers, 1);
ngx_conf_merge_msec_value(conf->lingering_time,
prev->lingering_time, 30000);
ngx_conf_merge_msec_value(conf->lingering_timeout,
@ -1545,6 +1536,7 @@ static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
port = ngx_atoi(&addr[p], args[1].len - p);
if (port == NGX_ERROR && p == 0) {
/* "listen host" */
@ -1564,9 +1556,10 @@ static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ls->addr = INADDR_ANY;
ls->port = (in_port_t) port;
return NGX_CONF_OK;
}
ls->port = (in_port_t) port;
} else {
ls->port = (in_port_t) port;
}
ls->addr = inet_addr((const char *) addr);
if (ls->addr == INADDR_NONE) {

View File

@ -164,7 +164,6 @@ struct ngx_http_core_loc_conf_s {
time_t keepalive_header; /* keepalive_timeout */
ngx_flag_t keepalive_buffers; /* keepalive_buffers */
ngx_flag_t sendfile; /* sendfile */
ngx_flag_t tcp_nopush; /* tcp_nopush */
ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */

View File

@ -197,7 +197,13 @@ static void ngx_http_init_request(ngx_event_t *rev)
hc = c->data;
if (hc == NULL) {
if (hc) {
#if (NGX_STAT_STUB)
(*ngx_stat_reading)++;
#endif
} else {
if (!(hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)))) {
#if (NGX_STAT_STUB)
@ -220,10 +226,6 @@ static void ngx_http_init_request(ngx_event_t *rev)
r->header_in = hc->busy[0];
}
#if (NGX_STAT_STUB)
(*ngx_stat_reading)++;
#endif
} else {
if (!(r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)))) {
@ -683,7 +685,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
/* NGX_AGAIN: a request line parsing is still incomplete */
if (r->header_in->last == r->header_in->end) {
if (r->header_in->pos == r->header_in->end) {
rv = ngx_http_alloc_large_header_buffer(r, 1);
@ -728,7 +730,7 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
if (rc == NGX_AGAIN) {
if (r->header_in->last == r->header_in->end) {
if (r->header_in->pos == r->header_in->end) {
rv = ngx_http_alloc_large_header_buffer(r, 0);
@ -971,6 +973,10 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
if (hc->nfree) {
b = hc->free[--hc->nfree];
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http large header free: " PTR_FMT " " SIZE_T_FMT,
b->pos, b->end - b->last);
} else if (hc->nbusy < cscf->large_client_header_buffers.num) {
if (hc->busy == NULL) {
@ -987,6 +993,10 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
return NGX_ERROR;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http large header alloc: " PTR_FMT " " SIZE_T_FMT,
b->pos, b->end - b->last);
} else {
return NGX_DECLINED;
}
@ -1005,12 +1015,15 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
return NGX_OK;
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http large header copy: %d", r->header_in->pos - old);
new = b->start;
ngx_memcpy(new, old, r->header_in->last - old);
ngx_memcpy(new, old, r->header_in->pos - old);
b->pos = new + (r->header_in->pos - old);
b->last = new + (r->header_in->last - old);
b->last = new + (r->header_in->pos - old);
if (request_line) {
r->request_start = new;
@ -1552,14 +1565,9 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
hc = r->http_connection;
b = r->header_in;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (b->pos < b->last) {
if (b->pos < b->last || clcf->keepalive_buffers) {
/*
* the pipelined request or we like to keep the allocated
* ngx_http_request_t and the client header buffers while keepalive
*/
/* the pipelined request */
if (b != c->buffer) {
@ -1570,6 +1578,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
if (hc->free == NULL) {
hc->free = ngx_palloc(c->pool,
cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *));
if (hc->free == NULL) {
ngx_http_close_connection(c);
return;
@ -1591,6 +1600,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
ngx_http_close_request(r, 0);
c->data = hc;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
ngx_add_timer(rev, clcf->keepalive_timeout);
if (ngx_handle_level_read_event(rev) == NGX_ERROR) {
@ -1603,8 +1613,6 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
if (b->pos < b->last) {
/* the pipelined request */
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request");
hc->pipeline = 1;
@ -1615,35 +1623,42 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
hc->pipeline = 0;
b->pos = b->last = b->start;
if (ngx_pfree(c->pool, r) == NGX_OK) {
hc->request = NULL;
}
if (!clcf->keepalive_buffers) {
b = c->buffer;
if (ngx_pfree(c->pool, r) == NGX_OK) {
hc->request = NULL;
if (ngx_pfree(c->pool, b->start) == NGX_OK) {
b->pos = NULL;
} else {
b->pos = b->start;
b->last = b->start;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: " PTR_FMT " %d",
hc->free, hc->nfree);
if (hc->free) {
for (i = 0; i < hc->nfree; i++) {
ngx_pfree(c->pool, hc->free[i]);
hc->free[i] = NULL;
}
if (ngx_pfree(c->pool, c->buffer->start) == NGX_OK) {
c->buffer = NULL;
hc->nfree = 0;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: " PTR_FMT " %d",
hc->busy, hc->nbusy);
if (hc->busy) {
for (i = 0; i < hc->nbusy; i++) {
ngx_pfree(c->pool, hc->busy[i]);
hc->busy[i] = NULL;
}
if (hc->free) {
for (i = 0; i < hc->nfree; i++) {
ngx_pfree(c->pool, hc->free[i]);
hc->free[i] = NULL;
}
hc->nfree = 0;
}
if (hc->busy) {
for (i = 0; i < hc->nbusy; i++) {
ngx_pfree(c->pool, hc->busy[i]);
hc->busy[i] = NULL;
}
hc->nbusy = 0;
}
hc->nbusy = 0;
}
rev->event_handler = ngx_http_keepalive_handler;
@ -1689,6 +1704,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
static void ngx_http_keepalive_handler(ngx_event_t *rev)
{
size_t size;
ssize_t n;
ngx_buf_t *b;
ngx_connection_t *c;
@ -1704,8 +1720,36 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
return;
}
ctx = (ngx_http_log_ctx_t *) rev->log->data;
#if (HAVE_KQUEUE)
if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) {
if (rev->pending_eof) {
ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno,
"kevent() reported that client %s closed "
"keepalive connection", ctx->client);
ngx_http_close_connection(c);
return;
}
}
#endif
hc = c->data;
b = hc->nbusy ? hc->busy[0] : c->buffer;
b = c->buffer;
size = b->end - b->start;
if (b->pos == NULL) {
if (!(b->pos = ngx_palloc(c->pool, size))) {
ngx_http_close_connection(c);
return;
}
b->start = b->pos;
b->last = b->pos;
b->end = b->pos + size;
}
/*
* MSIE closes a keepalive connection with RST flag
@ -1715,7 +1759,7 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
c->log_error = NGX_ERROR_IGNORE_ECONNRESET;
ngx_set_socket_errno(0);
n = c->recv(c, b->last, b->end - b->last);
n = c->recv(c, b->last, size);
c->log_error = NGX_ERROR_INFO;
if (n == NGX_AGAIN) {
@ -1727,7 +1771,6 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
return;
}
ctx = (ngx_http_log_ctx_t *) rev->log->data;
rev->log->handler = NULL;
if (n == 0) {

View File

@ -66,9 +66,9 @@ void ngx_debug_init()
#if (NGX_DEBUG && !NGX_NO_DEBUG_MALLOC)
#if __FreeBSD_version >= 500014
_malloc_options = "JAV";
_malloc_options = "J";
#else
malloc_options = "JAV";
malloc_options = "J";
#endif
#endif