line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::ServerName; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
148718
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
85
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
59
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
880
|
use parent qw(Plack::Middleware); |
|
2
|
|
|
|
|
310
|
|
|
2
|
|
|
|
|
11
|
|
7
|
2
|
|
|
2
|
|
45821
|
use Plack::Util; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
8
|
2
|
|
|
2
|
|
10
|
use vars qw( $VERSION ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1614
|
|
9
|
|
|
|
|
|
|
$VERSION = 0.02; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub call { |
12
|
3
|
|
|
3
|
1
|
60186
|
my ( $self, $env ) = @_; |
13
|
3
|
|
|
|
|
17
|
my $res = $self->app->($env); |
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
|
|
139
|
my $header_order = { |
16
|
|
|
|
|
|
|
'Apache/1.3.23' => [ qw( Date Server Last-Modified ETag Accept-Ranges Content-Length Keep-Alive Connection Content-Type ) ], |
17
|
|
|
|
|
|
|
'Apache/2.2.8' => [ qw( Date Server Last-Modified ETag Accept-Ranges Content-Length Keep-Alive Connection Content-Type ) ], |
18
|
|
|
|
|
|
|
'Microsoft-IIS/5.0' => [ qw( Server Expires Date Content-Type Accept-Ranges Last-Modified ETag Content-Length ) ], |
19
|
|
|
|
|
|
|
'Netscape-Enterprise/4.1' => [ qw( Server Date Content-type Last-modified Content-length Accept-ranges Connection ) ], |
20
|
|
|
|
|
|
|
'Sun-ONE-Web-Server/6.1' => [ qw( Server Date Content-length Content-type Last-Modified Etag Accept-Ranges Connection ) ], |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Plack::Util::response_cb( $res, sub { |
24
|
3
|
|
|
3
|
|
36
|
my $res = shift(); |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
|
|
5
|
my $headers = {}; |
27
|
3
|
|
|
|
|
5
|
my @orders = (); |
28
|
3
|
50
|
33
|
|
|
41
|
if( defined( $self->{order} ) and ( ref( $self->{order} ) eq 'ARRAY' ) ) { |
|
|
50
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
@orders = @{ $self->{order} }; |
|
0
|
|
|
|
|
0
|
|
30
|
|
|
|
|
|
|
} elsif( defined( $self->{name} ) and defined( $header_order->{ $self->{name} } ) and ( ref( $header_order->{ $self->{name} } ) eq 'ARRAY' ) ) { |
31
|
0
|
|
|
|
|
0
|
@orders = @{ $header_order->{ $self->{name} } }; |
|
0
|
|
|
|
|
0
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
4
|
my $h = HTTP::Headers->new( @{ $res->[1] } ); |
|
3
|
|
|
|
|
18
|
|
35
|
3
|
|
|
|
|
190
|
$h->scan( sub { push @{ $headers->{ lc( shift() ) } }, shift(); } ); |
|
5
|
|
|
|
|
60
|
|
|
5
|
|
|
|
|
21
|
|
36
|
3
|
50
|
33
|
|
|
25
|
$headers->{'last-modified'} = $headers->{'date'} if( defined( $headers->{'date'} ) and !defined( $headers->{'last-modified'} ) ); |
37
|
3
|
100
|
33
|
|
|
21
|
if( defined( $self->{name} ) ) { |
|
|
50
|
|
|
|
|
|
38
|
2
|
|
|
|
|
6
|
$headers->{'server'} = [ $self->{name} ]; |
39
|
|
|
|
|
|
|
} elsif( !defined( $self->{name} ) and defined( $headers->{'server'} ) ) { |
40
|
1
|
|
|
|
|
3
|
delete $headers->{'server'}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
5
|
my @output_headers = (); |
44
|
3
|
|
|
|
|
5
|
foreach my $order ( @orders ) { |
45
|
0
|
0
|
|
|
|
0
|
next if( !defined( $headers->{ lc( $order ) } ) ); |
46
|
0
|
|
|
|
|
0
|
push @output_headers, ( $order, $_ ) foreach ( @{ $headers->{ lc( $order ) } } ); |
|
0
|
|
|
|
|
0
|
|
47
|
0
|
|
|
|
|
0
|
delete $headers->{ lc( $order ) }; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
5
|
foreach my $header ( keys %{ $headers } ) { |
|
3
|
|
|
|
|
12
|
|
51
|
5
|
|
|
|
|
6
|
push @output_headers, ( ucfirst( $header ), $_ ) foreach ( @{ $headers->{ $header } } ); |
|
5
|
|
|
|
|
23
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
3
|
50
|
|
|
|
11
|
$res->[1] = \@output_headers if( scalar( @output_headers ) ); |
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
|
|
18
|
return; |
57
|
3
|
|
|
|
|
39
|
} ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
__END__ |