diff options
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/modules/ngx_http_charset_filter.c | 2 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_gzip_filter.c | 17 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_range_filter.c | 2 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_static_handler.c | 2 | ||||
| -rw-r--r-- | src/http/ngx_http.h | 1 | ||||
| -rw-r--r-- | src/http/ngx_http_copy_filter.c | 4 | ||||
| -rw-r--r-- | src/http/ngx_http_core_module.c | 11 | ||||
| -rw-r--r-- | src/http/ngx_http_core_module.h | 14 | ||||
| -rw-r--r-- | src/http/ngx_http_filter.h | 24 | ||||
| -rw-r--r-- | src/http/ngx_http_request.c | 29 | ||||
| -rw-r--r-- | src/http/ngx_http_request.h | 6 |
11 files changed, 66 insertions, 46 deletions
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c index 279001baf..b79a4606c 100644 --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -184,7 +184,7 @@ static int ngx_http_charset_header_filter(ngx_http_request_t *r) ngx_http_create_ctx(r, ctx, ngx_http_charset_filter_module, sizeof(ngx_http_charset_ctx_t), NGX_ERROR); - r->filter |= NGX_HTTP_FILTER_NEED_IN_MEMORY; + r->filter_need_in_memory = 1; return ngx_http_next_header_filter(r); } diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index eb9497517..cc7ba9c28 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -317,7 +317,7 @@ static int ngx_http_gzip_header_filter(ngx_http_request_t *r) r->headers_out.content_length->key.len = 0; r->headers_out.content_length = NULL; } - r->filter |= NGX_HTTP_FILTER_NEED_IN_MEMORY; + r->filter_need_in_memory = 1; return ngx_http_next_header_filter(r); } @@ -438,12 +438,12 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) * We preallocate a memory for zlib in one buffer (200K-400K), this * dicreases a number of malloc() and free() calls and also probably * dicreases a number of syscalls (sbrk() or so). - * Besides we free() this memory as soon as the gzipping will complete + * Besides we free this memory as soon as the gzipping will complete * and do not wait while a whole response will be sent to a client. * * 8K is for zlib deflate_state (~6K). * - * TODO: 64-bit, round to PAGE_SIZE, autoconf of deflate_state size + * TODO: 64-bit, autoconf of deflate_state size */ ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9)); @@ -739,10 +739,12 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size) alloc = items * size; if (alloc % 512 != 0) { - /* we allocate 8K for zlib deflate_state (~6K) */ - /* TODO: PAGE_SIZE */ + /* + * allocate the zlib deflate_state, it takes about 6K on x86, + * we allocate 8K + */ - alloc = (alloc + 4095) & ~4095; + alloc = (alloc + ngx_pagesize - 1) & ~(ngx_pagesize - 1); } if (alloc <= ctx->allocated) { @@ -900,8 +902,7 @@ static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf, ngx_conf_merge_value(conf->enable, prev->enable, 0); - ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, - /* STUB: PAGE_SIZE */ 4096); + ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, ngx_pagesize); ngx_conf_merge_unsigned_value(conf->http_version, prev->http_version, NGX_HTTP_VERSION_11); diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c index 484bcb07b..65a5fd055 100644 --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -113,7 +113,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) if (r->http_version < NGX_HTTP_VERSION_10 || r->headers_out.status != NGX_HTTP_OK || r->headers_out.content_length_n == -1 - || !(r->filter & NGX_HTTP_FILTER_ALLOW_RANGES)) + || !r->filter_allow_ranges) { return ngx_http_next_header_filter(r); } diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c index 532e8faab..9c11c7eb1 100644 --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -480,7 +480,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) return NGX_HTTP_INTERNAL_SERVER_ERROR; } - r->filter |= NGX_HTTP_FILTER_ALLOW_RANGES; + r->filter_allow_ranges = 1; rc = ngx_http_send_header(r); if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h index bb718549b..87eabd1d2 100644 --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -16,7 +16,6 @@ typedef struct ngx_http_cleanup_s ngx_http_cleanup_t; #include <ngx_http_request.h> #include <ngx_http_config.h> #include <ngx_http_busy_lock.h> -#include <ngx_http_filter.h> #include <ngx_http_log_handler.h> #include <ngx_http_core_module.h> diff --git a/src/http/ngx_http_copy_filter.c b/src/http/ngx_http_copy_filter.c index 96da0a517..6d901a467 100644 --- a/src/http/ngx_http_copy_filter.c +++ b/src/http/ngx_http_copy_filter.c @@ -75,8 +75,8 @@ ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in) sizeof(ngx_output_chain_ctx_t), NGX_ERROR); ctx->sendfile = r->sendfile; - ctx->need_in_memory = r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY; - ctx->need_in_temp = r->filter & NGX_HTTP_FILTER_NEED_TEMP; + ctx->need_in_memory = r->filter_need_in_memory; + ctx->need_in_temp = r->filter_need_temporary; ctx->pool = r->pool; ctx->bufs = conf->bufs; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index aeec7d21c..f68a60573 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -227,6 +227,13 @@ static ngx_command_t ngx_http_core_commands[] = { offsetof(ngx_http_core_loc_conf_t, lingering_timeout), NULL }, + { ngx_string("reset_timedout_connection"), + 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, reset_timedout_connection), + NULL }, + { ngx_string("msie_padding"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_flag_slot, @@ -1238,7 +1245,7 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; lcf->lingering_time = NGX_CONF_UNSET_MSEC; lcf->lingering_timeout = NGX_CONF_UNSET_MSEC; - + lcf->reset_timedout_connection = NGX_CONF_UNSET; lcf->msie_padding = NGX_CONF_UNSET; return lcf; @@ -1326,6 +1333,8 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_msec_value(conf->lingering_timeout, prev->lingering_timeout, 5000); + ngx_conf_merge_value(conf->reset_timedout_connection, + prev->reset_timedout_connection, 0); ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1); if (conf->open_files == NULL) { diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index a8a6cf0ef..9224e9553 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -137,6 +137,7 @@ typedef struct { ngx_flag_t sendfile; /* sendfile */ ngx_flag_t tcp_nopush; /* tcp_nopush */ + ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */ ngx_flag_t msie_padding; /* msie_padding */ ngx_array_t *error_pages; /* error_page */ @@ -172,4 +173,17 @@ int ngx_http_internal_redirect(ngx_http_request_t *r, ngx_str_t *uri, ngx_str_t *args); +typedef int (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r); +typedef int (*ngx_http_output_body_filter_pt) + (ngx_http_request_t *r, ngx_chain_t *chain); + + +int ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain); +int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain); + + +extern ngx_http_output_header_filter_pt ngx_http_top_header_filter; +extern ngx_http_output_body_filter_pt ngx_http_top_body_filter; + + #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */ diff --git a/src/http/ngx_http_filter.h b/src/http/ngx_http_filter.h deleted file mode 100644 index d90947f05..000000000 --- a/src/http/ngx_http_filter.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _NGX_HTTP_FILTER_H_INCLUDED_ -#define _NGX_HTTP_FILTER_H_INCLUDED_ - - -#define NGX_HTTP_FILTER_NEED_IN_MEMORY 1 -#define NGX_HTTP_FILTER_SSI_NEED_IN_MEMORY 2 -#define NGX_HTTP_FILTER_NEED_TEMP 4 -#define NGX_HTTP_FILTER_ALLOW_RANGES 8 - - -typedef int (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r); -typedef int (*ngx_http_output_body_filter_pt) - (ngx_http_request_t *r, ngx_chain_t *chain); - - -int ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain); -int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain); - - -extern ngx_http_output_header_filter_pt ngx_http_top_header_filter; -extern ngx_http_output_body_filter_pt ngx_http_top_body_filter; - - -#endif /* _NGX_HTTP_FILTER_H_INCLUDED_ */ diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 97e1b9439..98fbc28a6 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -90,7 +90,7 @@ void ngx_http_init_connection(ngx_connection_t *c) /* STUB: epoll edge */ c->write->event_handler = ngx_http_empty_handler; if (rev->ready) { - /* deferred accept, aio, iocp */ + /* the deferred accept(), rtsig, aio, iocp */ if (ngx_accept_mutex) { if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { @@ -1542,10 +1542,12 @@ int ngx_http_send_last(ngx_http_request_t *r) void ngx_http_close_request(ngx_http_request_t *r, int error) { - ngx_uint_t i; - ngx_log_t *log; - ngx_http_log_ctx_t *ctx; - ngx_http_cleanup_t *cleanup; + ngx_uint_t i; + ngx_log_t *log; + ngx_http_log_ctx_t *ctx; + ngx_http_cleanup_t *cleanup; + ngx_http_core_loc_conf_t *clcf; + struct linger l; log = r->connection->log; @@ -1610,6 +1612,22 @@ void ngx_http_close_request(ngx_http_request_t *r, int error) } } + if (r->connection->timedout) { + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + + if (clcf->reset_timedout_connection) { + l.l_onoff = 1; + l.l_linger = 0; + + if (setsockopt(r->connection->fd, SOL_SOCKET, SO_LINGER, + (const void *) &l, sizeof(struct linger)) == -1) + { + ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, + "setsockopt(SO_LINGER) failed"); + } + } + } + /* ctx->url was allocated from r->pool */ ctx = log->data; ctx->url = NULL; @@ -1676,6 +1694,7 @@ static void ngx_http_client_error(ngx_http_request_t *r, if (error == NGX_HTTP_REQUEST_TIME_OUT) { ngx_log_error(NGX_LOG_INFO, r->connection->log, NGX_ETIMEDOUT, "client timed out"); + r->connection->timedout = 1; ngx_http_close_request(r, error); ngx_http_close_connection(r->connection); return; diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index cac8aed37..3cf7307b2 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -287,8 +287,10 @@ struct ngx_http_request_s { unsigned lingering_close:1; unsigned closed:1; - /* TODO: use the filter flags or the separate bits ???? */ - u_int filter; + unsigned filter_need_in_memory:1; + unsigned filter_ssi_need_in_memory:1; + unsigned filter_need_temporary:1; + unsigned filter_allow_ranges:1; /* used to parse HTTP headers */ ngx_int_t state; |
