File Coverage

blib/lib/Plack/Middleware/NoMultipleSlashes.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 19 19 100.0


line stmt bran cond sub pod time code
1 1     1   3889 use strict;
  1         3  
  1         68  
2 1     1   7 use warnings;
  1         2  
  1         77  
3             package Plack::Middleware::NoMultipleSlashes;
4             BEGIN {
5 1     1   33 $Plack::Middleware::NoMultipleSlashes::VERSION = '0.001';
6             }
7             # ABSTRACT: Remove multiple slashes in your paths automatically
8              
9 1     1   8 use parent qw(Plack::Middleware);
  1         2  
  1         13  
10              
11             sub call {
12 5     5 1 83909 my($self, $env) = @_;
13 5         31 $env->{'PATH_INFO'} =~ s{/+}{/}g;
14 5         35 $self->app->($env);
15             };
16              
17             1;
18              
19              
20              
21             =pod
22              
23             =head1 NAME
24              
25             Plack::Middleware::NoMultipleSlashes - Remove multiple slashes in your paths automatically
26              
27             =head1 VERSION
28              
29             version 0.001
30              
31             =head1 SYNOPSIS
32              
33             Pure Plack:
34              
35             # in your app.psgi
36             use Plack::Builder;
37              
38             my $app = sub { ... };
39              
40             builder {
41             enable 'NoMultipleSlashes';
42             $app;
43             };
44              
45             Or in your Dancer app:
46              
47             # in config.yml
48             plack_middlewares:
49             - [ NoMultipleSlashes ]
50              
51             =head1 DESCRIPTION
52              
53             In short: this removes all multiple slashes from your B. Read on,
54             if you care why.
55              
56             Multiple slashes in requests are a common problem, which many share.
57             Apparently, the RFC states that you should be able to expect different results
58             from I and I (notice the second slash), so
59             if the frameworks wish to maintain RFC compatibility, they cannot remove those
60             extra slashes for you.
61              
62             While you can handle this issue in a reverse proxy, in a rewrite module or
63             in your code, I find it more comfortable to have Plack take care of it in the
64             thin layer called Middlewares.
65              
66             By enabling this middleware, all multiple slashes in your requests will
67             automatically be cut. I becomes I. Simple as
68             that.
69              
70             =head1 ORIGIN
71              
72             This Plack middleware was written originally after the issue was raised in
73             the L (L) community.
74              
75             If you're using Dancer, this is the prefered way to handle this issue.
76              
77             =head1 AUTHOR
78              
79             Sawyer X
80              
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is copyright (c) 2011 by Sawyer X.
84              
85             This is free software; you can redistribute it and/or modify it under
86             the same terms as the Perl 5 programming language system itself.
87              
88             =cut
89              
90              
91             __END__