Skip to content

Commit

Permalink
Fix: subrange does not work when use internal redirect(rewrite) on ra…
Browse files Browse the repository at this point in the history
…nge request
  • Loading branch information
renyongquan committed Jun 30, 2014
1 parent 1e8bce3 commit 535f6a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions ngx_http_subrange_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ static ngx_int_t ngx_http_subrange_init(ngx_conf_t *cf){
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
/* Register to NGX_HTTP_ACCESS_PHASE phase, so the handler only takes effect on
* main request
* */
h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
if(h == NULL){
return NGX_ERROR;
Expand Down Expand Up @@ -566,6 +569,13 @@ static ngx_int_t ngx_http_subrange_set_header_handler(ngx_http_request_t *r){
if(rlcf->size == NGX_CONF_UNSET || rlcf->size == 0){
return NGX_DECLINED;
}
/*Maybe Range has been added if this is a internal redirect*/
if(r->internal){
ctx = ngx_http_get_module_ctx(r->main, ngx_http_subrange_filter_module);
if(ctx != NULL){
return NGX_DECLINED;
}
}
ctx = ngx_palloc(r->pool, sizeof(ngx_http_subrange_filter_ctx_t));
if(ctx == NULL){
return NGX_ERROR;
Expand All @@ -581,11 +591,6 @@ static ngx_int_t ngx_http_subrange_set_header_handler(ngx_http_request_t *r){
ngx_memzero(&ctx->checkpoint, sizeof(ngx_http_subrange_checkpoint_t));

ngx_http_set_ctx(r, ctx, ngx_http_subrange_filter_module);
if(r == r->main){
if(r->internal && r->headers_in.range){ //internal redirect main request, Range has been added
return NGX_DECLINED;
}
}
/*TODO process if-range*/

/*Not a range request*/
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_subrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ void test_ngx_http_subrange_parse(){
assert(range.start == 5250276732);
assert(range.end == (ngx_uint_t) -1);
assert(range.total == 0);
printf("%lu, %lu, %lu", range.start, range.end, range.total);
pass("test_ngx_http_subrange_parse: range absent end");

/*test invalid range case*/
Expand Down Expand Up @@ -736,6 +735,7 @@ void test_ngx_http_subrange_body_filter(){
rlcf = ngx_http_get_module_loc_conf((&r), ngx_http_subrange_module);

/*untouched*/
in = NULL;
ctx->touched = 0;
assert(ngx_http_subrange_body_filter(&r, in) == NGX_OK);

Expand Down

0 comments on commit 535f6a4

Please sign in to comment.