# HG changeset patch # User Maxim Dounin # Date 1221739148 -14400 # Node ID c65888a079bfd96a2eedb308c9d5c7b4f7de6296 # Parent 2f3f9dbf84d0cf6aa471072bc52411c63bc614e4# Parent b453a4324c60689e0def20c4fcd1311726726640 Merge with current. diff --git a/auto/modules b/auto/modules --- a/auto/modules +++ b/auto/modules @@ -117,6 +117,8 @@ if [ $HTTP_GZIP = YES ]; then HTTP_SRCS="$HTTP_SRCS $HTTP_GZIP_SRCS" fi +HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_RANGE_LATE_FILTER_MODULE" + if [ $HTTP_POSTPONE = YES ]; then HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_POSTPONE_FILTER_MODULE" HTTP_SRCS="$HTTP_SRCS $HTTP_POSTPONE_FILTER_SRCS" diff --git a/auto/sources b/auto/sources --- a/auto/sources +++ b/auto/sources @@ -267,6 +267,7 @@ HTTP_HEADERS_FILTER_MODULE=ngx_http_head HTTP_RANGE_HEADER_FILTER_MODULE=ngx_http_range_header_filter_module HTTP_RANGE_BODY_FILTER_MODULE=ngx_http_range_body_filter_module +HTTP_RANGE_LATE_FILTER_MODULE=ngx_http_range_late_filter_module HTTP_NOT_MODIFIED_FILTER_MODULE=ngx_http_not_modified_filter_module diff --git a/src/http/modules/ngx_http_range_filter_module.c b/src/http/modules/ngx_http_range_filter_module.c --- a/src/http/modules/ngx_http_range_filter_module.c +++ b/src/http/modules/ngx_http_range_filter_module.c @@ -68,12 +68,15 @@ static ngx_int_t ngx_http_range_not_sati static ngx_int_t ngx_http_range_test_overlapped(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in); static ngx_int_t ngx_http_range_singlepart_body(ngx_http_request_t *r, - ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in); + ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in, + ngx_http_output_body_filter_pt ngx_http_next_body_filter); static ngx_int_t ngx_http_range_multipart_body(ngx_http_request_t *r, - ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in); + ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in, + ngx_http_output_body_filter_pt ngx_http_next_body_filter); static ngx_int_t ngx_http_range_header_filter_init(ngx_conf_t *cf); static ngx_int_t ngx_http_range_body_filter_init(ngx_conf_t *cf); +static ngx_int_t ngx_http_range_late_filter_init(ngx_conf_t *cf); static ngx_http_module_t ngx_http_range_header_filter_module_ctx = { @@ -138,8 +141,40 @@ ngx_module_t ngx_http_range_body_filter }; +static ngx_http_module_t ngx_http_range_late_filter_module_ctx = { + NULL, /* preconfiguration */ + ngx_http_range_late_filter_init, /* postconfiguration */ + + NULL, /* create main configuration */ + NULL, /* init main configuration */ + + NULL, /* create server configuration */ + NULL, /* merge server configuration */ + + NULL, /* create location configuration */ + NULL, /* merge location configuration */ +}; + + +ngx_module_t ngx_http_range_late_filter_module = { + NGX_MODULE_V1, + &ngx_http_range_late_filter_module_ctx, /* module context */ + NULL, /* module directives */ + NGX_HTTP_MODULE, /* module type */ + NULL, /* init master */ + NULL, /* init module */ + NULL, /* init process */ + NULL, /* init thread */ + NULL, /* exit thread */ + NULL, /* exit process */ + NULL, /* exit master */ + NGX_MODULE_V1_PADDING +}; + + static ngx_http_output_header_filter_pt ngx_http_next_header_filter; -static ngx_http_output_body_filter_pt ngx_http_next_body_filter; +static ngx_http_output_body_filter_pt ngx_http_next_body_early_filter; +static ngx_http_output_body_filter_pt ngx_http_next_body_late_filter; static ngx_int_t @@ -537,7 +572,8 @@ ngx_http_range_not_satisfiable(ngx_http_ static ngx_int_t -ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in) +ngx_http_range_body_generic_filter(ngx_http_request_t *r, ngx_chain_t *in, + ngx_http_output_body_filter_pt ngx_http_next_body_filter) { ngx_http_range_filter_ctx_t *ctx; @@ -552,7 +588,8 @@ ngx_http_range_body_filter(ngx_http_requ } if (ctx->ranges.nelts == 1) { - return ngx_http_range_singlepart_body(r, ctx, in); + return ngx_http_range_singlepart_body(r, ctx, in, + ngx_http_next_body_filter); } /* @@ -567,7 +604,8 @@ ngx_http_range_body_filter(ngx_http_requ return NGX_ERROR; } - return ngx_http_range_multipart_body(r, ctx, in); + return ngx_http_range_multipart_body(r, ctx, in, + ngx_http_next_body_filter); } @@ -620,7 +658,8 @@ overlapped: static ngx_int_t ngx_http_range_singlepart_body(ngx_http_request_t *r, - ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in) + ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in, + ngx_http_output_body_filter_pt ngx_http_next_body_filter) { off_t start, last; ngx_buf_t *buf; @@ -700,7 +739,8 @@ ngx_http_range_singlepart_body(ngx_http_ static ngx_int_t ngx_http_range_multipart_body(ngx_http_request_t *r, - ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in) + ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in, + ngx_http_output_body_filter_pt ngx_http_next_body_filter) { ngx_buf_t *b, *buf; ngx_uint_t i; @@ -829,6 +869,30 @@ ngx_http_range_multipart_body(ngx_http_r static ngx_int_t +ngx_http_range_body_early_filter(ngx_http_request_t *r, ngx_chain_t *in) +{ + if (!r->allow_ranges || r->late_ranges) { + return ngx_http_next_body_early_filter(r, in); + } + + return ngx_http_range_body_generic_filter(r, in, + ngx_http_next_body_early_filter); +} + + +static ngx_int_t +ngx_http_range_body_late_filter(ngx_http_request_t *r, ngx_chain_t *in) +{ + if (!r->allow_ranges || !r->late_ranges) { + return ngx_http_next_body_late_filter(r, in); + } + + return ngx_http_range_body_generic_filter(r, in, + ngx_http_next_body_late_filter); +} + + +static ngx_int_t ngx_http_range_header_filter_init(ngx_conf_t *cf) { ngx_http_next_header_filter = ngx_http_top_header_filter; @@ -841,8 +905,18 @@ ngx_http_range_header_filter_init(ngx_co static ngx_int_t ngx_http_range_body_filter_init(ngx_conf_t *cf) { - ngx_http_next_body_filter = ngx_http_top_body_filter; - ngx_http_top_body_filter = ngx_http_range_body_filter; + ngx_http_next_body_early_filter = ngx_http_top_body_filter; + ngx_http_top_body_filter = ngx_http_range_body_early_filter; return NGX_OK; } + + +static ngx_int_t +ngx_http_range_late_filter_init(ngx_conf_t *cf) +{ + ngx_http_next_body_late_filter = ngx_http_top_body_filter; + ngx_http_top_body_filter = ngx_http_range_body_late_filter; + + return NGX_OK; +} diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -472,6 +472,7 @@ struct ngx_http_request_s { unsigned filter_need_in_memory:1; unsigned filter_need_temporary:1; unsigned allow_ranges:1; + unsigned late_ranges:1; #if (NGX_STAT_STUB) unsigned stat_reading:1;