aboutsummaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'src/http')
-rw-r--r--src/http/ngx_http_core_module.c10
-rw-r--r--src/http/ngx_http_core_module.h1
-rw-r--r--src/http/ngx_http_event.c12
3 files changed, 23 insertions, 0 deletions
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 9b9d20958..3ca006d97 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -134,6 +134,13 @@ static ngx_command_t ngx_http_core_commands[] = {
offsetof(ngx_http_core_loc_conf_t, send_timeout),
NULL},
+ {ngx_string("keepalive_timeout"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_msec_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_core_loc_conf_t, keepalive_timeout),
+ 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,
@@ -912,6 +919,7 @@ static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool)
lcf->send_timeout = NGX_CONF_UNSET;
lcf->discarded_buffer_size = NGX_CONF_UNSET;
+ lcf->keepalive_timeout = NGX_CONF_UNSET;
lcf->lingering_time = NGX_CONF_UNSET;
lcf->lingering_timeout = NGX_CONF_UNSET;
@@ -981,6 +989,8 @@ static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
ngx_conf_merge_size_value(conf->discarded_buffer_size,
prev->discarded_buffer_size, 1500);
+ ngx_conf_merge_msec_value(conf->keepalive_timeout, prev->keepalive_timeout,
+ 70000);
ngx_conf_merge_msec_value(conf->lingering_time, prev->lingering_time,
30000);
ngx_conf_merge_msec_value(conf->lingering_timeout, prev->lingering_timeout,
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index cfe0d91a5..2a94ea450 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -100,6 +100,7 @@ typedef struct {
ngx_msec_t send_timeout; /* send_timeout */
size_t send_lowat; /* send_lowa */
size_t discarded_buffer_size; /* discarded_buffer_size */
+ ngx_msec_t keepalive_timeout; /* keepalive_timeout */
ngx_msec_t lingering_time; /* lingering_time */
ngx_msec_t lingering_timeout; /* lingering_timeout */
diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c
index f14dd96ff..83f0f688d 100644
--- a/src/http/ngx_http_event.c
+++ b/src/http/ngx_http_event.c
@@ -996,6 +996,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
ngx_connection_t *c;
ngx_http_log_ctx_t *ctx;
ngx_http_core_main_conf_t *cmcf;
+ ngx_http_core_loc_conf_t *clcf;
c = (ngx_connection_t *) r->connection;
rev = c->read;
@@ -1004,6 +1005,17 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
ctx->action = "closing request";
ngx_http_close_request(r, 0);
+ if (rev->timer_set) {
+ ngx_del_timer(rev);
+ } else {
+ rev->timer_set = 1;
+ }
+
+ clcf = (ngx_http_core_loc_conf_t *)
+ ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
+
+ ngx_add_timer(rev, clcf->keepalive_timeout);
+
if (rev->blocked && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) {
if (ngx_add_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT) == NGX_ERROR) {
ngx_http_close_connection(c);