mirror of
https://github.com/nginx/nginx.git
synced 2024-11-28 08:09:00 +08:00
nginx-0.0.12-2004-09-23-20:39:34 import
This commit is contained in:
parent
f7abd72716
commit
236e045751
@ -2,7 +2,7 @@
|
|||||||
#define _NGINX_H_INCLUDED_
|
#define _NGINX_H_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
#define NGINX_VER "nginx/0.0.11"
|
#define NGINX_VER "nginx/0.0.12"
|
||||||
|
|
||||||
#define NGINX_VAR "NGINX"
|
#define NGINX_VAR "NGINX"
|
||||||
#define NGX_NEWPID_EXT ".newbin"
|
#define NGX_NEWPID_EXT ".newbin"
|
||||||
|
@ -37,14 +37,24 @@ typedef struct {
|
|||||||
} ngx_http_rewrite_srv_conf_t;
|
} 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 void *ngx_http_rewrite_create_srv_conf(ngx_conf_t *cf);
|
||||||
static char *ngx_http_rewrite_merge_srv_conf(ngx_conf_t *cf,
|
static char *ngx_http_rewrite_merge_srv_conf(ngx_conf_t *cf,
|
||||||
void *parent, void *child);
|
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,
|
static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf);
|
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_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[] = {
|
static ngx_command_t ngx_http_rewrite_commands[] = {
|
||||||
|
|
||||||
{ ngx_string("rewrite"),
|
{ ngx_string("rewrite"),
|
||||||
@ -54,6 +64,13 @@ static ngx_command_t ngx_http_rewrite_commands[] = {
|
|||||||
0,
|
0,
|
||||||
NULL },
|
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_string("rewrite_log"),
|
||||||
NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
||||||
ngx_conf_set_flag_slot,
|
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_create_srv_conf, /* create server configuration */
|
||||||
ngx_http_rewrite_merge_srv_conf, /* merge 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 */
|
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)
|
static void *ngx_http_rewrite_create_srv_conf(ngx_conf_t *cf)
|
||||||
{
|
{
|
||||||
ngx_http_rewrite_srv_conf_t *conf;
|
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,
|
static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf)
|
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)
|
static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
ngx_http_handler_pt *h;
|
ngx_http_handler_pt *h;
|
||||||
|
@ -401,7 +401,7 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev)
|
|||||||
|
|
||||||
if (!p->cachable && p->upstream->peer.connection) {
|
if (!p->cachable && p->upstream->peer.connection) {
|
||||||
ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
|
ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
|
||||||
"kevent() reported that client have closed "
|
"kevent() reported that client closed "
|
||||||
"prematurely connection, "
|
"prematurely connection, "
|
||||||
"so upstream connection is closed too");
|
"so upstream connection is closed too");
|
||||||
ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
|
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,
|
ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
|
||||||
"kevent() reported that client have closed "
|
"kevent() reported that client closed "
|
||||||
"prematurely connection");
|
"prematurely connection");
|
||||||
|
|
||||||
if (p->upstream == NULL || p->upstream->peer.connection == NULL) {
|
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) {
|
if (!p->cachable && p->upstream->peer.connection) {
|
||||||
ngx_log_error(NGX_LOG_INFO, ev->log, err,
|
ngx_log_error(NGX_LOG_INFO, ev->log, err,
|
||||||
"client have closed prematurely connection, "
|
"client closed prematurely connection, "
|
||||||
"so upstream connection is closed too");
|
"so upstream connection is closed too");
|
||||||
ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
|
ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_log_error(NGX_LOG_INFO, ev->log, err,
|
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) {
|
if (p->upstream == NULL || p->upstream->peer.connection == NULL) {
|
||||||
ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
|
ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
|
||||||
|
@ -234,13 +234,6 @@ static ngx_command_t ngx_http_core_commands[] = {
|
|||||||
0,
|
0,
|
||||||
NULL },
|
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_string("lingering_time"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||||
ngx_conf_set_msec_slot,
|
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->limit_rate = NGX_CONF_UNSET_SIZE;
|
||||||
lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
|
lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
|
||||||
lcf->keepalive_header = NGX_CONF_UNSET;
|
lcf->keepalive_header = NGX_CONF_UNSET;
|
||||||
lcf->keepalive_buffers = NGX_CONF_UNSET;
|
|
||||||
lcf->lingering_time = NGX_CONF_UNSET_MSEC;
|
lcf->lingering_time = NGX_CONF_UNSET_MSEC;
|
||||||
lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
|
lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
|
||||||
lcf->reset_timedout_connection = NGX_CONF_UNSET;
|
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);
|
prev->keepalive_timeout, 75000);
|
||||||
ngx_conf_merge_sec_value(conf->keepalive_header,
|
ngx_conf_merge_sec_value(conf->keepalive_header,
|
||||||
prev->keepalive_header, 0);
|
prev->keepalive_header, 0);
|
||||||
ngx_conf_merge_value(conf->keepalive_buffers, prev->keepalive_buffers, 1);
|
|
||||||
ngx_conf_merge_msec_value(conf->lingering_time,
|
ngx_conf_merge_msec_value(conf->lingering_time,
|
||||||
prev->lingering_time, 30000);
|
prev->lingering_time, 30000);
|
||||||
ngx_conf_merge_msec_value(conf->lingering_timeout,
|
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);
|
port = ngx_atoi(&addr[p], args[1].len - p);
|
||||||
|
|
||||||
if (port == NGX_ERROR && p == 0) {
|
if (port == NGX_ERROR && p == 0) {
|
||||||
|
|
||||||
/* "listen host" */
|
/* "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->addr = INADDR_ANY;
|
||||||
ls->port = (in_port_t) port;
|
ls->port = (in_port_t) port;
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
}
|
|
||||||
|
|
||||||
|
} else {
|
||||||
ls->port = (in_port_t) port;
|
ls->port = (in_port_t) port;
|
||||||
|
}
|
||||||
|
|
||||||
ls->addr = inet_addr((const char *) addr);
|
ls->addr = inet_addr((const char *) addr);
|
||||||
if (ls->addr == INADDR_NONE) {
|
if (ls->addr == INADDR_NONE) {
|
||||||
|
@ -164,7 +164,6 @@ struct ngx_http_core_loc_conf_s {
|
|||||||
|
|
||||||
time_t keepalive_header; /* keepalive_timeout */
|
time_t keepalive_header; /* keepalive_timeout */
|
||||||
|
|
||||||
ngx_flag_t keepalive_buffers; /* keepalive_buffers */
|
|
||||||
ngx_flag_t sendfile; /* sendfile */
|
ngx_flag_t sendfile; /* sendfile */
|
||||||
ngx_flag_t tcp_nopush; /* tcp_nopush */
|
ngx_flag_t tcp_nopush; /* tcp_nopush */
|
||||||
ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */
|
ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */
|
||||||
|
@ -197,7 +197,13 @@ static void ngx_http_init_request(ngx_event_t *rev)
|
|||||||
|
|
||||||
hc = c->data;
|
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 (!(hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)))) {
|
||||||
|
|
||||||
#if (NGX_STAT_STUB)
|
#if (NGX_STAT_STUB)
|
||||||
@ -220,10 +226,6 @@ static void ngx_http_init_request(ngx_event_t *rev)
|
|||||||
r->header_in = hc->busy[0];
|
r->header_in = hc->busy[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (NGX_STAT_STUB)
|
|
||||||
(*ngx_stat_reading)++;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!(r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)))) {
|
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 */
|
/* 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);
|
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 (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);
|
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) {
|
if (hc->nfree) {
|
||||||
b = hc->free[--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) {
|
} else if (hc->nbusy < cscf->large_client_header_buffers.num) {
|
||||||
|
|
||||||
if (hc->busy == NULL) {
|
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;
|
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 {
|
} else {
|
||||||
return NGX_DECLINED;
|
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;
|
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;
|
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->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) {
|
if (request_line) {
|
||||||
r->request_start = new;
|
r->request_start = new;
|
||||||
@ -1552,14 +1565,9 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
|
|||||||
hc = r->http_connection;
|
hc = r->http_connection;
|
||||||
b = r->header_in;
|
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 */
|
||||||
|
|
||||||
/*
|
|
||||||
* the pipelined request or we like to keep the allocated
|
|
||||||
* ngx_http_request_t and the client header buffers while keepalive
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (b != c->buffer) {
|
if (b != c->buffer) {
|
||||||
|
|
||||||
@ -1570,6 +1578,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
|
|||||||
if (hc->free == NULL) {
|
if (hc->free == NULL) {
|
||||||
hc->free = ngx_palloc(c->pool,
|
hc->free = ngx_palloc(c->pool,
|
||||||
cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *));
|
cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *));
|
||||||
|
|
||||||
if (hc->free == NULL) {
|
if (hc->free == NULL) {
|
||||||
ngx_http_close_connection(c);
|
ngx_http_close_connection(c);
|
||||||
return;
|
return;
|
||||||
@ -1591,6 +1600,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
|
|||||||
ngx_http_close_request(r, 0);
|
ngx_http_close_request(r, 0);
|
||||||
c->data = hc;
|
c->data = hc;
|
||||||
|
|
||||||
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
ngx_add_timer(rev, clcf->keepalive_timeout);
|
ngx_add_timer(rev, clcf->keepalive_timeout);
|
||||||
|
|
||||||
if (ngx_handle_level_read_event(rev) == NGX_ERROR) {
|
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) {
|
if (b->pos < b->last) {
|
||||||
|
|
||||||
/* the pipelined request */
|
|
||||||
|
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request");
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request");
|
||||||
|
|
||||||
hc->pipeline = 1;
|
hc->pipeline = 1;
|
||||||
@ -1615,18 +1623,23 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
|
|||||||
|
|
||||||
hc->pipeline = 0;
|
hc->pipeline = 0;
|
||||||
|
|
||||||
b->pos = b->last = b->start;
|
|
||||||
|
|
||||||
if (!clcf->keepalive_buffers) {
|
|
||||||
|
|
||||||
if (ngx_pfree(c->pool, r) == NGX_OK) {
|
if (ngx_pfree(c->pool, r) == NGX_OK) {
|
||||||
hc->request = NULL;
|
hc->request = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ngx_pfree(c->pool, c->buffer->start) == NGX_OK) {
|
b = c->buffer;
|
||||||
c->buffer = 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) {
|
if (hc->free) {
|
||||||
for (i = 0; i < hc->nfree; i++) {
|
for (i = 0; i < hc->nfree; i++) {
|
||||||
ngx_pfree(c->pool, hc->free[i]);
|
ngx_pfree(c->pool, hc->free[i]);
|
||||||
@ -1636,6 +1649,9 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
|
|||||||
hc->nfree = 0;
|
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) {
|
if (hc->busy) {
|
||||||
for (i = 0; i < hc->nbusy; i++) {
|
for (i = 0; i < hc->nbusy; i++) {
|
||||||
ngx_pfree(c->pool, hc->busy[i]);
|
ngx_pfree(c->pool, hc->busy[i]);
|
||||||
@ -1644,7 +1660,6 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
|
|||||||
|
|
||||||
hc->nbusy = 0;
|
hc->nbusy = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
rev->event_handler = ngx_http_keepalive_handler;
|
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)
|
static void ngx_http_keepalive_handler(ngx_event_t *rev)
|
||||||
{
|
{
|
||||||
|
size_t size;
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
ngx_buf_t *b;
|
ngx_buf_t *b;
|
||||||
ngx_connection_t *c;
|
ngx_connection_t *c;
|
||||||
@ -1704,8 +1720,36 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
|
|||||||
return;
|
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;
|
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
|
* 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;
|
c->log_error = NGX_ERROR_IGNORE_ECONNRESET;
|
||||||
ngx_set_socket_errno(0);
|
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;
|
c->log_error = NGX_ERROR_INFO;
|
||||||
|
|
||||||
if (n == NGX_AGAIN) {
|
if (n == NGX_AGAIN) {
|
||||||
@ -1727,7 +1771,6 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = (ngx_http_log_ctx_t *) rev->log->data;
|
|
||||||
rev->log->handler = NULL;
|
rev->log->handler = NULL;
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
|
@ -66,9 +66,9 @@ void ngx_debug_init()
|
|||||||
#if (NGX_DEBUG && !NGX_NO_DEBUG_MALLOC)
|
#if (NGX_DEBUG && !NGX_NO_DEBUG_MALLOC)
|
||||||
|
|
||||||
#if __FreeBSD_version >= 500014
|
#if __FreeBSD_version >= 500014
|
||||||
_malloc_options = "JAV";
|
_malloc_options = "J";
|
||||||
#else
|
#else
|
||||||
malloc_options = "JAV";
|
malloc_options = "J";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user