… | |
… | |
183 | |
183 | |
184 | sub response { |
184 | sub response { |
185 | my ($self, $code, $msg, $hdr, $content) = @_; |
185 | my ($self, $code, $msg, $hdr, $content) = @_; |
186 | my $res = "HTTP/1.1 $code $msg\015\012"; |
186 | my $res = "HTTP/1.1 $code $msg\015\012"; |
187 | |
187 | |
188 | $self->{h}{connection} = "close" if $hdr->{Connection} =~ /close/; |
188 | if (exists $hdr->{Connection}) { |
|
|
189 | if ($hdr->{Connection} =~ /close/) { |
|
|
190 | $self->{h}{connection} = "close" |
|
|
191 | } |
|
|
192 | } else { |
|
|
193 | if ($self->{version} < 1.1) { |
|
|
194 | if ($self->{h}{connection} =~ /keep-alive/i) { |
|
|
195 | $hdr->{Connection} = "Keep-Alive"; |
|
|
196 | } else { |
|
|
197 | $self->{h}{connection} = "close" |
|
|
198 | } |
|
|
199 | } |
|
|
200 | } |
189 | |
201 | |
190 | $res .= "Date: $HTTP_NOW\015\012"; |
202 | $res .= "Date: $HTTP_NOW\015\012"; |
191 | |
203 | |
192 | while (my ($h, $v) = each %$hdr) { |
204 | while (my ($h, $v) = each %$hdr) { |
193 | $res .= "$h: $v\015\012" |
205 | $res .= "$h: $v\015\012" |
… | |
… | |
338 | |
350 | |
339 | $self->eoconn; |
351 | $self->eoconn; |
340 | |
352 | |
341 | die if $@ && !ref $@; |
353 | die if $@ && !ref $@; |
342 | |
354 | |
343 | last if $self->{h}{connection} =~ /close/ || $self->{version} < 1.1; |
355 | last if $self->{h}{connection} =~ /close/; |
344 | |
356 | |
345 | $httpevent->broadcast; |
357 | $httpevent->broadcast; |
346 | |
358 | |
347 | $fh->timeout($::PER_TIMEOUT); |
359 | $fh->timeout($::PER_TIMEOUT); |
348 | } |
360 | } |
… | |
… | |
420 | } else { |
432 | } else { |
421 | $ims < $self->{stat}[9] |
433 | $ims < $self->{stat}[9] |
422 | or $self->err(304, "not modified"); |
434 | or $self->err(304, "not modified"); |
423 | |
435 | |
424 | if (-r "$path/index.html") { |
436 | if (-r "$path/index.html") { |
425 | $self->{path} .= "/index.html"; |
437 | # replace directory "size" by index.html filesize |
|
|
438 | $self->{stat}[7] = (stat ($self->{path} .= "/index.html"))[7]; |
426 | $self->handle_file; |
439 | $self->handle_file; |
427 | } else { |
440 | } else { |
428 | $self->handle_dir; |
441 | $self->handle_dir; |
429 | } |
442 | } |
430 | } |
443 | } |
… | |
… | |
481 | my $delay = $::NOW + $::PER_TIMEOUT + 15; |
494 | my $delay = $::NOW + $::PER_TIMEOUT + 15; |
482 | while (%{$uri{$self->{remote_id}}{$self->{uri}}} > 1) { |
495 | while (%{$uri{$self->{remote_id}}{$self->{uri}}} > 1) { |
483 | if ($delay <= $::NOW) { |
496 | if ($delay <= $::NOW) { |
484 | $self->err_segmented_download; |
497 | $self->err_segmented_download; |
485 | } else { |
498 | } else { |
486 | $httpevent->broadcast; |
499 | $httpevent->wait; |
487 | } |
500 | } |
488 | } |
501 | } |
489 | } |
502 | } |
490 | |
503 | |
491 | $hdr->{"Content-Range"} = "bytes $l-$h/$length"; |
504 | $hdr->{"Content-Range"} = "bytes $l-$h/$length"; |