diff options
Diffstat (limited to 'src/http')
-rw-r--r-- | src/http/modules/ngx_http_not_modified_filter.c | 4 | ||||
-rw-r--r-- | src/http/modules/ngx_http_static_handler.c | 17 | ||||
-rw-r--r-- | src/http/ngx_http.h | 1 | ||||
-rw-r--r-- | src/http/ngx_http_output_filter.c | 11 | ||||
-rw-r--r-- | src/http/ngx_http_request.c (renamed from src/http/ngx_http_event.c) | 39 | ||||
-rw-r--r-- | src/http/ngx_http_special_response.c | 8 | ||||
-rw-r--r-- | src/http/ngx_http_write_filter.c | 8 |
7 files changed, 78 insertions, 10 deletions
diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter.c index ab22fa682..f1ccd4456 100644 --- a/src/http/modules/ngx_http_not_modified_filter.c +++ b/src/http/modules/ngx_http_not_modified_filter.c @@ -39,7 +39,7 @@ static int ngx_http_not_modified_header_filter(ngx_http_request_t *r) if (r->headers_out.status != NGX_HTTP_OK || r->headers_in.if_modified_since == NULL - || r->headers_out.last_modified_time == NULL) + || r->headers_out.last_modified_time == -1) { return next_header_filter(r); } @@ -50,7 +50,7 @@ static int ngx_http_not_modified_header_filter(ngx_http_request_t *r) ngx_log_debug(r->connection->log, "%d %d" _ ims _ r->headers_out.last_modified_time); - /* I think that the date equality is correcter */ + /* I think that the equality of the dates is correcter */ if (ims != NGX_ERROR && ims == r->headers_out.last_modified_time) { r->headers_out.status = NGX_HTTP_NOT_MODIFIED; diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c index 8ea6a0a00..784f3de4d 100644 --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -118,6 +118,7 @@ int ngx_http_static_handler(ngx_http_request_t *r) } /* we need to allocate all before the header would be sent */ + ngx_test_null(h, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), NGX_HTTP_INTERNAL_SERVER_ERROR); @@ -132,18 +133,28 @@ int ngx_http_static_handler(ngx_http_request_t *r) } if (r->header_only) { + ngx_http_finalize_request(r, rc); + +#if 0 if (rc == NGX_AGAIN) { ngx_http_set_write_handler(r); } else { ngx_http_finalize_request(r, 0); } +#endif return NGX_OK; } - h->type = NGX_HUNK_FILE|NGX_HUNK_LAST; +#if 0 + h->type = r->main ? NGX_HUNK_FILE : NGX_HUNK_FILE|NGX_HUNK_LAST; +#else + h->type = NGX_HUNK_FILE; +#endif + + h->file_pos = 0; h->file_last = ngx_file_size(r->file.info); @@ -152,6 +163,9 @@ int ngx_http_static_handler(ngx_http_request_t *r) rc = ngx_http_output_filter(r, h); + ngx_http_finalize_request(r, rc); + +#if 0 if (r->main == NULL) { if (rc == NGX_AGAIN) { ngx_http_set_write_handler(r); @@ -160,6 +174,7 @@ int ngx_http_static_handler(ngx_http_request_t *r) ngx_http_finalize_request(r, 0); } } +#endif return NGX_OK; } diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h index 4cdd4c608..3cdd120c5 100644 --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -54,6 +54,7 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int error); void ngx_http_set_write_handler(ngx_http_request_t *r); +int ngx_http_send_last(ngx_http_request_t *r); void ngx_http_close_request(ngx_http_request_t *r, int error); void ngx_http_close_connection(ngx_connection_t *c); diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c index 06120769f..6de920215 100644 --- a/src/http/ngx_http_output_filter.c +++ b/src/http/ngx_http_output_filter.c @@ -72,10 +72,11 @@ ngx_module_t ngx_http_output_filter_module = { #define ngx_next_filter (*ngx_http_top_body_filter) #define need_to_copy(r, hunk) \ - (((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) \ - && (hunk->type & NGX_HUNK_IN_MEMORY) == 0) \ - || ((r->filter & NGX_HTTP_FILTER_NEED_TEMP) \ - && (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP)))) + (!ngx_hunk_special(hunk) \ + && (((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) \ + && (hunk->type & NGX_HUNK_IN_MEMORY) == 0) \ + || ((r->filter & NGX_HTTP_FILTER_NEED_TEMP) \ + && (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP))))) @@ -201,6 +202,8 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk) *ctx->last_out = ce; ctx->last_out = &ce->next; ctx->hunk = NULL; + + break; } if (ctx->out == NULL && last != NGX_NONE) { diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_request.c index ea8120764..0f66b0d40 100644 --- a/src/http/ngx_http_event.c +++ b/src/http/ngx_http_request.c @@ -785,6 +785,10 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int error) int rc; ngx_event_t *rev, *wev; + if (r->main) { + return; + } + rc = error; if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { @@ -813,9 +817,25 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int error) return; } +#if 1 + return; +#endif + } else if (rc == NGX_ERROR) { r->keepalive = 0; r->lingering_close = 0; + + } else { + if (ngx_http_send_last(r) == NGX_ERROR) { + ngx_http_close_request(r, 0); + ngx_http_close_connection(r->connection); + return; + } + + if (rc == NGX_AGAIN) { + ngx_http_set_write_handler(r); + return; + } } rev = r->connection->read; @@ -840,6 +860,8 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int error) ngx_http_close_request(r, 0); ngx_http_close_connection(r->connection); } + + return; } @@ -887,6 +909,8 @@ void ngx_http_set_write_handler(ngx_http_request_t *r) ngx_http_close_request(r, 0); ngx_http_close_connection(r->connection); } + + return; } @@ -951,6 +975,8 @@ static void ngx_http_writer(ngx_event_t *wev) ngx_http_close_request(r, 0); ngx_http_close_connection(r->connection); } + + return; } @@ -1046,6 +1072,8 @@ static void ngx_http_read_discarded_body_event(ngx_event_t *rev) ngx_http_close_request(r, rc); ngx_http_close_connection(c); } + + return; } @@ -1385,6 +1413,17 @@ static void ngx_http_empty_handler(ngx_event_t *wev) } +int ngx_http_send_last(ngx_http_request_t *r) +{ + ngx_hunk_t *h; + + ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); + h->type = NGX_HUNK_LAST; + + return ngx_http_output_filter(r, h); +} + + void ngx_http_close_request(ngx_http_request_t *r, int error) { ngx_http_log_ctx_t *ctx; diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c index 9e3bb9ae3..736211654 100644 --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -199,15 +199,19 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error) } rc = ngx_http_send_header(r); + if (rc == NGX_ERROR) { return NGX_ERROR; } if (r->header_only) { + ngx_http_finalize_request(r, rc); +#if 0 if (rc == NGX_AGAIN) { ngx_http_set_write_handler(r); return NGX_AGAIN; } +#endif return NGX_OK; } @@ -248,12 +252,16 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error) rc = ngx_http_output_filter(r, h); + ngx_http_finalize_request(r, rc); + +#if 0 if (r->main == NULL) { if (rc == NGX_AGAIN) { ngx_http_set_write_handler(r); return NGX_AGAIN; } } +#endif return NGX_OK; diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c index 26c632c62..3f43875bc 100644 --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -130,14 +130,16 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) last _ flush _ size); #endif - /* avoid the output if there is no last hunk, no flush point and - size of the hunks is smaller then "buffer_output" */ + /* + * avoid the output if there is no last hunk, no flush point and + * size of the hunks is smaller then "buffer_output" + */ if (!last && flush == 0 && size < conf->buffer_output) { return NGX_OK; } - if (r->connection->write->delayed) { + if (!r->connection->write->ready || r->connection->write->delayed) { return NGX_AGAIN; } |