… | |
… | |
176 | sub err_blocked { |
176 | sub err_blocked { |
177 | my $self = shift; |
177 | my $self = shift; |
178 | my $ip = $self->{remote_addr}; |
178 | my $ip = $self->{remote_addr}; |
179 | my $time = time2str $blocked{$ip} = $::NOW + $::BLOCKTIME; |
179 | my $time = time2str $blocked{$ip} = $::NOW + $::BLOCKTIME; |
180 | |
180 | |
181 | Coro::Event::do_timer(after => 15); |
181 | Coro::Event::do_timer(after => 20*rand); |
182 | |
182 | |
183 | $self->err(401, "too many connections", |
183 | $self->err(401, "too many connections", |
184 | { |
184 | { |
185 | "Content-Type" => "text/html", |
185 | "Content-Type" => "text/html", |
186 | "Retry-After" => $::BLOCKTIME |
186 | "Retry-After" => $::BLOCKTIME, |
|
|
187 | "Warning" => "Please do NOT retry, you have been blocked", |
|
|
188 | "WWW-Authenticate" => "Basic realm=\"Please do NOT retry, you have been blocked\"", |
187 | }, |
189 | }, |
188 | <<EOF); |
190 | <<EOF); |
189 | <html><p> |
191 | <html><p> |
190 | You have been blocked because you opened too many connections. You |
192 | You have been blocked because you opened too many connections. You |
191 | may retry at</p> |
193 | may retry at</p> |
… | |
… | |
243 | |
245 | |
244 | $self->{method} = $1; |
246 | $self->{method} = $1; |
245 | $self->{uri} = $2; |
247 | $self->{uri} = $2; |
246 | $self->{version} = $3; |
248 | $self->{version} = $3; |
247 | |
249 | |
248 | $3 eq "1.0" or $3 eq "1.1" |
250 | $3 =~ /^1\./ |
249 | or $self->err(506, "http protocol version $3 not supported"); |
251 | or $self->err(506, "http protocol version $3 not supported"); |
250 | |
252 | |
251 | # parse headers |
253 | # parse headers |
252 | { |
254 | { |
253 | my (%hdr, $h, $v); |
255 | my (%hdr, $h, $v); |
… | |
… | |
427 | goto ignore; |
429 | goto ignore; |
428 | } |
430 | } |
429 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h > $l; |
431 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h > $l; |
430 | } |
432 | } |
431 | $hdr->{"Content-Range"} = "bytes */$length"; |
433 | $hdr->{"Content-Range"} = "bytes */$length"; |
|
|
434 | $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")"); |
432 | $self->err(416, "not satisfiable", $hdr); |
435 | $self->err(416, "not satisfiable", $hdr); |
433 | |
436 | |
434 | satisfiable: |
437 | satisfiable: |
435 | # check for segmented downloads |
438 | # check for segmented downloads |
436 | if ($l && $::NO_SEGMENTED) { |
439 | if ($l && $::NO_SEGMENTED) { |