Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

init

  • Loading branch information...
commit c7d163dc1c65021e45e70e6bc334d8e652e3ad6b 1 parent 0b9f5de
Kazuhiro Osawa authored
3  Makefile.PL
View
@@ -5,7 +5,8 @@ readme_from 'lib/Plack/Midelware/ErrorpageRedirectloopDefence.pm';
readme_markdown_from 'lib/Plack/Midelware/ErrorpageRedirectloopDefence.pm';
githubmeta;
-# requires '';
+requires 'parent';
+requires 'Plack::Request';
tests 't/*.t';
author_tests 'xt';
48 lib/Plack/Middleware/ErrorpageRedirectloopDefence.pm
View
@@ -0,0 +1,48 @@
+package Plack::Middleware::ErrorpageRedirectloopDefence;
+use strict;
+use warnings;
+use parent qw(Plack::Middleware);
+our $VERSION = '0.09';
+
+use Plack::Request;
+
+sub call {
+ my $self = shift;
+ my $env = shift;
+ my $req = Plack::Request->new($env);
+
+ if ($req->uri eq $req->header('referer')) {
+ return [ 204, [ 'Content-Type', 'text/html', 'Content-Length', '0' ], [ '' ] ];
+ }
+
+ $self->app->($env);
+}
+
+
+1;
+__END__
+
+=head1 NAME
+
+Plack::Midelware::ErrorpageRedirectloopDefence -
+
+=head1 SYNOPSIS
+
+ use Plack::Midelware::ErrorpageRedirectloopDefence;
+
+=head1 DESCRIPTION
+
+Plack::Midelware::ErrorpageRedirectloopDefence is
+
+=head1 AUTHOR
+
+Kazuhiro Osawa E<lt>yappo {at} shibuya {dot} plE<gt>
+
+=head1 SEE ALSO
+
+=head1 LICENSE
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
30 sample.pl
View
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use File::Spec;
+use File::Basename;
+use lib File::Spec->catdir(dirname(__FILE__), 'lib');
+warn File::Spec->catdir(dirname(__FILE__), 'lib');
+
+use Plack::Builder;
+use Plack::Request;
+
+my $html = <<'HTML';
+<html>
+ <head>
+ <title>error</title>
+ <meta http-equiv="refresh" content="3;URL=%s">
+ </head>
+ <body>now: %d, %s</body>
+</html>
+HTML
+
+builder {
+ enable 'ErrorpageRedirectloopDefence';
+ sub {
+ my $req = Plack::Request->new(shift);
+ my $body = sprintf $html, $req->uri, time(), $req->uri;
+ [ 502, [ 'Content-Type', 'text/html', 'Content-Length', length($body) ], [ $body ] ];
+ };
+};
+
Please sign in to comment.
Something went wrong with that request. Please try again.