# HG changeset patch # User Maxim Dounin # Date 1268332037 -10800 # Node ID f3a9e57d2e179caeb8ec67e729ffec113b4f9dc3 # Parent 5f4de8cf0d9d664a3f71fa99c288763830200477# Parent dd7104f21940d9026698b6db4a52622f49745caa Merge with current. diff --git a/auto/modules b/auto/modules --- a/auto/modules +++ b/auto/modules @@ -126,6 +126,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 @@ -265,6 +265,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 @@ -541,7 +576,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; @@ -556,7 +592,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); } /* @@ -571,7 +608,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); } @@ -624,7 +662,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; @@ -710,7 +749,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) { off_t body_start; ngx_buf_t *b, *buf; @@ -846,6 +886,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; @@ -858,8 +922,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_postpone_filter_module.c b/src/http/ngx_http_postpone_filter_module.c 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 @@ -508,6 +508,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;