blib/lib/Plack/Middleware/NoMultipleSlashes.pm

filter: Statementstmt 100% 14 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 100% 20 / 20 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Plack::Middleware::NoMultipleSlashes;
4 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 $Plack::Middleware::NoMultipleSlashes::VERSION = '0.001';
6 }
7 # ABSTRACT: Remove multiple slashes in your paths automatically
8  
9 2 ▶use parent qw(Plack::Middleware);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 ▶sub call {
Subroutine call: called CC=1 SCAR=0.0
Pod documented
12 5 my($self, $env) = @_;
13 5 $env->{'PATH_INFO'} =~ s{/+}{/}g;
14 5 $self->app->($env);
15 };
16  
17 2 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<PATH_INFO>. 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<http://server/> and I<http://server//> (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<//hello///world> becomes I</hello/world>. 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<Dancer> (L<http://perldancer.org>) 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 <xsawyerx@cpan.org>
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__
↑ Summary