… | |
… | |
78 | |
78 | |
79 | Event->io(fd => Linux::AIO::poll_fileno, |
79 | Event->io(fd => Linux::AIO::poll_fileno, |
80 | poll => 'r', async => 1, |
80 | poll => 'r', async => 1, |
81 | cb => \&Linux::AIO::poll_cb); |
81 | cb => \&Linux::AIO::poll_cb); |
82 | |
82 | |
83 | our %conn; # $conn{ip}{fh} => connobj |
83 | our %conn; # $conn{ip}{self} => connobj |
|
|
84 | our %uri; # $uri{ip}{uri}{self} |
84 | our %blocked; |
85 | our %blocked; |
85 | our %mimetype; |
86 | our %mimetype; |
86 | |
87 | |
87 | sub read_mimetypes { |
88 | sub read_mimetypes { |
88 | local *M; |
89 | local *M; |
… | |
… | |
127 | delete $conn{$self->{remote_addr}}{$self*1}; |
128 | delete $conn{$self->{remote_addr}}{$self*1}; |
128 | } |
129 | } |
129 | |
130 | |
130 | # end of connection |
131 | # end of connection |
131 | sub eoconn { |
132 | sub eoconn { |
|
|
133 | my $self = shift; |
132 | delete $uri{$self->{remote_addr}}{$self->{uri}}{$self*1}; |
134 | delete $uri{$self->{remote_addr}}{$self->{uri}}{$self*1}; |
133 | } |
135 | } |
134 | |
136 | |
135 | sub slog { |
137 | sub slog { |
136 | my $self = shift; |
138 | my $self = shift; |
… | |
… | |
276 | eval { |
278 | eval { |
277 | $self->map_uri; |
279 | $self->map_uri; |
278 | $self->respond; |
280 | $self->respond; |
279 | }; |
281 | }; |
280 | |
282 | |
|
|
283 | $self->eoconn; |
|
|
284 | |
281 | die if $@ && !ref $@; |
285 | die if $@ && !ref $@; |
282 | |
|
|
283 | $self->eoconn; |
|
|
284 | |
286 | |
285 | last if $self->{h}{connection} =~ /close/ || $self->{version} lt "1.1"; |
287 | last if $self->{h}{connection} =~ /close/ || $self->{version} lt "1.1"; |
286 | |
288 | |
287 | $self->slog(9, "persistent connection [".$self->{h}{"user-agent"}."][$self->{reqs}]"); |
289 | $self->slog(9, "persistent connection [".$self->{h}{"user-agent"}."][$self->{reqs}]"); |
288 | $fh->timeout($::PER_TIMEOUT); |
290 | $fh->timeout($::PER_TIMEOUT); |
… | |
… | |
428 | ($l, $h) = ($1, ($2 ne "" || $2 >= $length) ? $2 : $length - 1); |
430 | ($l, $h) = ($1, ($2 ne "" || $2 >= $length) ? $2 : $length - 1); |
429 | } else { |
431 | } else { |
430 | ($l, $h) = (0, $length - 1); |
432 | ($l, $h) = (0, $length - 1); |
431 | goto ignore; |
433 | goto ignore; |
432 | } |
434 | } |
433 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h > $l; |
435 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h >= $l; |
434 | } |
436 | } |
435 | $hdr->{"Content-Range"} = "bytes */$length"; |
437 | $hdr->{"Content-Range"} = "bytes */$length"; |
436 | $hdr->{"Content-Length"} = $length; |
438 | $hdr->{"Content-Length"} = $length; |
437 | $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")"); |
439 | $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")"); |
438 | $self->err(416, "not satisfiable", $hdr, ""); |
440 | $self->err(416, "not satisfiable", $hdr, ""); |
439 | |
441 | |
440 | satisfiable: |
442 | satisfiable: |
441 | # check for segmented downloads |
443 | # check for segmented downloads |
442 | if ($l && $::NO_SEGMENTED) { |
444 | if ($l && $::NO_SEGMENTED) { |
443 | if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { |
445 | if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { |
444 | Coro::Event::do_timer(after => 15); |
|
|
445 | |
|
|
446 | $self->err(400, "segmented downloads are not allowed"); |
446 | $self->err(400, "segmented downloads are not allowed"); |
447 | } |
447 | } |
448 | } |
448 | } |
449 | |
449 | |
450 | $hdr->{"Content-Range"} = "bytes $l-$h/$length"; |
450 | $hdr->{"Content-Range"} = "bytes $l-$h/$length"; |