Perl модуль и докачка

Igor Sysoev is at rambler-co.ru
Thu Dec 28 21:51:02 MSK 2006


On Thu, 28 Dec 2006, Konstantin Petrenko wrote:

> Наткнулся на очень не приятный глюк. Файло отдается модулем на перле:
> ===
> ...
>      if( -e $fn){
>        $r->variable("sid",$sid);
>        $r->allow_ranges;
>        $r->header_out("Content-Length", -s $fn);
>        $r->send_http_header;
>        $r->sendfile($fn);
>        return OK;
>      }
>      else{
>        return HTTP_NOT_FOUND;
>      }
> ...
> ===
> Но, если прервать закачку и потом возобновить - то файлы как-бы
> докачивается но на самом деле отдается заного. В итоге содердимое
> файла превращается в кашу. Идет кусок сначала, потом где была прервана
> закачка, фаил начинается опять сначала.
>
> nginx/0.5.4, ОС FreeBSD 6.2-PRE
> в конфиге написано так:
> ===
>        location /downloads {
>            set $sid 1;
>            perl getfile::handler;
>        }
> ===

Прилагаемый патч должен исправить ошибку.


Игорь Сысоев
http://sysoev.ru
-------------- next part --------------
Index: src/http/modules/perl/ngx_http_perl_module.c
===================================================================
--- src/http/modules/perl/ngx_http_perl_module.c	(revision 278)
+++ src/http/modules/perl/ngx_http_perl_module.c	(working copy)
@@ -261,6 +261,12 @@
         return;
     }
 
+    if (r->allow_ranges) {
+        ctx->done = 1;
+        ngx_http_finalize_request(r, rc);
+        return;
+    }
+
     if (rc == NGX_OK || rc == NGX_HTTP_OK) {
         ngx_http_send_special(r, NGX_HTTP_LAST);
         ctx->done = 1;
Index: src/http/modules/perl/nginx.xs
===================================================================
--- src/http/modules/perl/nginx.xs	(revision 278)
+++ src/http/modules/perl/nginx.xs	(working copy)
@@ -675,6 +675,10 @@
     b->file->fd = fd;
     b->file->log = r->connection->log;
 
+    if (r->allow_ranges) {
+        b->last_buf = 1;
+    }
+
     (void) ngx_http_perl_output(r, b);
 
     XSRETURN_EMPTY;
Index: src/http/modules/ngx_http_range_filter_module.c
===================================================================
--- src/http/modules/ngx_http_range_filter_module.c	(revision 278)
+++ src/http/modules/ngx_http_range_filter_module.c	(working copy)
@@ -335,6 +335,11 @@
 
         r->headers_out.content_length_n = range->end - range->start;
 
+	if (r->headers_out.content_length) {
+	    r->headers_out.content_length->hash = 0;
+	    r->headers_out.content_length = NULL;
+	}
+
         return ngx_http_next_header_filter(r);
     }
 


More information about the nginx-ru mailing list