… | |
… | |
149 | } |
149 | } |
150 | $res .= "\015\012"; |
150 | $res .= "\015\012"; |
151 | |
151 | |
152 | $res .= $content if defined $content and $self->{method} ne "HEAD"; |
152 | $res .= $content if defined $content and $self->{method} ne "HEAD"; |
153 | |
153 | |
154 | print STDERR "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n";#d# |
154 | print STDERR "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n"; |
155 | |
155 | |
156 | $self->{written} += |
156 | $self->{written} += |
157 | print {$self->{fh}} $res; |
157 | print {$self->{fh}} $res; |
158 | } |
158 | } |
159 | |
159 | |
… | |
… | |
271 | |
271 | |
272 | $self->{server_port} = $self->{h}{host} =~ s/:([0-9]+)$// ? $1 : 80; |
272 | $self->{server_port} = $self->{h}{host} =~ s/:([0-9]+)$// ? $1 : 80; |
273 | |
273 | |
274 | weaken ($uri{$self->{remote_addr}}{$self->{uri}}{$self*1} = $self); |
274 | weaken ($uri{$self->{remote_addr}}{$self->{uri}}{$self*1} = $self); |
275 | |
275 | |
|
|
276 | eval { |
276 | $self->map_uri; |
277 | $self->map_uri; |
277 | $self->respond; |
278 | $self->respond; |
|
|
279 | }; |
|
|
280 | |
|
|
281 | die if $@ && !ref $@; |
278 | |
282 | |
279 | $self->eoconn; |
283 | $self->eoconn; |
280 | |
284 | |
281 | last if $self->{h}{connection} =~ /close/ || $self->{version} lt "1.1"; |
285 | last if $self->{h}{connection} =~ /close/ || $self->{version} lt "1.1"; |
282 | |
286 | |
… | |
… | |
377 | $self->err(301, "moved permanently", { Location => "http://$host$self->{uri}/" }); |
381 | $self->err(301, "moved permanently", { Location => "http://$host$self->{uri}/" }); |
378 | } else { |
382 | } else { |
379 | $ims < $self->{stat}[9] |
383 | $ims < $self->{stat}[9] |
380 | or $self->err(304, "not modified"); |
384 | or $self->err(304, "not modified"); |
381 | |
385 | |
382 | if ($self->{method} eq "GET") { |
|
|
383 | if (-r "$path/index.html") { |
386 | if (-r "$path/index.html") { |
384 | $self->{path} .= "/index.html"; |
387 | $self->{path} .= "/index.html"; |
385 | $self->handle_file; |
388 | $self->handle_file; |
386 | } else { |
389 | } else { |
387 | $self->handle_dir; |
390 | $self->handle_dir; |
388 | } |
|
|
389 | } |
391 | } |
390 | } |
392 | } |
391 | } elsif (-f _ && -r _) { |
393 | } elsif (-f _ && -r _) { |
392 | -x _ and $self->err(403, "forbidden"); |
394 | -x _ and $self->err(403, "forbidden"); |
393 | $self->handle_file; |
395 | $self->handle_file; |
… | |
… | |
429 | goto ignore; |
431 | goto ignore; |
430 | } |
432 | } |
431 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h > $l; |
433 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h > $l; |
432 | } |
434 | } |
433 | $hdr->{"Content-Range"} = "bytes */$length"; |
435 | $hdr->{"Content-Range"} = "bytes */$length"; |
|
|
436 | $hdr->{"Content-Length"} = $length; |
434 | $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")"); |
437 | $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")"); |
435 | $self->err(416, "not satisfiable", $hdr); |
438 | $self->err(416, "not satisfiable", $hdr, ""); |
436 | |
439 | |
437 | satisfiable: |
440 | satisfiable: |
438 | # check for segmented downloads |
441 | # check for segmented downloads |
439 | if ($l && $::NO_SEGMENTED) { |
442 | if ($l && $::NO_SEGMENTED) { |
440 | if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { |
443 | if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { |