Plack::Middleware::Cerberus - Include geo, time zone, user-agent and throttling from App::Cerberus
version 0.04
use Plack::Builder; my $app = sub { my $env = shift; my $time_zone = $env->{'plack.cerberus'}{tz}{name}; ... }; builder { enable 'Cerberus', servers => 'http://localhost:5001/'; $app; };
Plack::Middleware::Cerberus adds metadata from an App::Cerberus server to the $env as $env->{'plack.cerberus'}.
$env
$env->{'plack.cerberus'}
For instance:
Geo-location
Time zone
User-agent info
Are they a spider?
Are they making too many requests? Should we throttle them?
It can also be configured to throttle or ban IP address ranges with App::Cerberus::Plugin::Throttle.
The basic configuration (servers and timeout) are passed to "new()" in App::Cerberus::Client.
servers
timeout
enable 'Cerberus', servers => 'http://localhost:5001/', timeout => 0.1;
Or
enable 'Cerberus', servers => [ 'http://host1:5001/', 'http://host2:5001/'] timeout => 0.1;
If you are using the App::Cerberus::Plugin::Throttle plugin, then you can also configure:
enable 'Cerberus', servers => 'http://localhost:5001/', enforce => 1, log_as => 'warn';
If log_as is one of debug, info, warn, error or fatal, then Throttle messages will be logged at that level. It defaults to warn. If no logger is configured, then log_as is ignored and it always warns.
log_as
debug
info
warn
error
fatal
If enforce is true, then banned IP addresses will receive a 403 Forbidden response and throttled users a 503 Service Unavailable response, with a Retry-After: $seconds header.
enforce
403 Forbidden
503 Service Unavailable
Retry-After: $seconds
The $env variable will contain a key 'plack.cerberus' with any data that App::Cerberus has returned, for instance:
'plack.cerberus'
my $app = sub { my $env = shift; my $geo_info = $env->{'plack.cerberus'}{geo}; my $time_zone = $env->{'plack.cerberus'}{tz}; my $user_agent = $env->{'plack.cerberus'}{ua}; my $throttle = $env->{'plack.cerberus'}{throttle}; };
App::Cerberus
Dancer::Plugin::Cerberus
You can find documentation for this module with the perldoc command.
perldoc Plack::Middleware::Cerberus
You can also look for information at:
GitHub
http://github.com/clintongormley/Plack-Middleware-Cerberus
CPAN Ratings
http://cpanratings.perl.org/d/Plack-Middleware-Cerberus
Search MetaCPAN
https://metacpan.org/module/Plack::Middleware::Cerberus
Clinton Gormley <drtech@cpan.org>
This software is copyright (c) 2012 by Clinton Gormley.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Plack::Middleware::Cerberus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Cerberus
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Cerberus
For more information on module installation, please visit the detailed CPAN module installation guide.