| 1 | # $Id: /mirror/gungho/lib/Gungho/Component/Throttle.pm 31302 2007-11-29T11:52:09.725591Z lestrrat $ | ||
| 2 | # | ||
| 3 | # Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> | ||
| 4 | |||
| 5 | package Gungho::Component::Throttle; | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use base qw(Gungho::Component); | ||
| 9 | |||
| 10 | sub feature_name { 'Throttle' } | ||
| 11 | |||
| 12 | sub throttle | ||
| 13 | { | ||
| 14 | my $c = shift; | ||
| 15 | $c->log->debug( $_[0]->url . " NOT throttled" ); | ||
| 16 | return 1; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub send_request | ||
| 20 | { | ||
| 21 | my ($c, $request) = @_; | ||
| 22 | |||
| 23 | if (! $request->notes('original_host') && ! $c->throttle($request)) { | ||
| 24 | $c->log->debug("[THROTTLE] Request " . $request->url . " (" . $request->id . ") was throttled"); | ||
| 25 | $c->pushback_request($request); | ||
| 26 | return 0; | ||
| 27 | } else { | ||
| 28 | return $c->next::method($request); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | 1; | ||
| 33 | |||
| 34 | __END__ |