line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Session::State::Mixin::ResponseFilter; |
2
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
89
|
|
3
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
66
|
|
4
|
3
|
|
|
3
|
|
15
|
use Exporter 'import'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1131
|
|
5
|
|
|
|
|
|
|
our @EXPORT_OK = qw/response_filter/; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub response_filter { |
8
|
9
|
|
|
9
|
0
|
600
|
my ($self, $session_id, $res) = @_; |
9
|
9
|
100
|
|
|
|
100
|
Carp::croak "missing session_id" unless $session_id; |
10
|
|
|
|
|
|
|
|
11
|
8
|
100
|
|
|
|
38
|
if (Scalar::Util::blessed $res) { |
12
|
6
|
100
|
100
|
|
|
14
|
if ($res->code == 302) { |
|
|
100
|
100
|
|
|
|
|
13
|
2
|
100
|
|
|
|
18
|
if (my $uri = $res->header('Location')) { |
14
|
1
|
|
|
|
|
34
|
$res->header('Location' => $self->redirect_filter($session_id, $uri)); |
15
|
|
|
|
|
|
|
} |
16
|
2
|
|
|
|
|
103
|
return $res; |
17
|
|
|
|
|
|
|
} elsif ($res->content && ($res->header('Content-Type')||'text/html') =~ /html/) { |
18
|
2
|
|
|
|
|
169
|
$res->content( $self->html_filter($session_id, $res->content) ); |
19
|
2
|
|
|
|
|
5135
|
return $res; |
20
|
|
|
|
|
|
|
} else { |
21
|
2
|
|
|
|
|
74
|
return $res; # nop |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} else { |
24
|
|
|
|
|
|
|
# psgi |
25
|
2
|
100
|
|
|
|
12
|
if ($res->[0] == 302) { |
|
|
50
|
|
|
|
|
|
26
|
1
|
|
|
|
|
3
|
my @headers = @{ $res->[1] }; # copy |
|
1
|
|
|
|
|
4
|
|
27
|
1
|
|
|
|
|
10
|
my @new_headers; |
28
|
1
|
|
|
|
|
6
|
while ( my ( $key, $val ) = splice @headers, 0, 2 ) { |
29
|
1
|
50
|
|
|
|
4
|
if (lc($key) eq 'location') { |
30
|
1
|
|
|
|
|
6
|
$val = $self->redirect_filter($session_id, $val); |
31
|
|
|
|
|
|
|
} |
32
|
1
|
|
|
|
|
25
|
push @new_headers, $key, $val; |
33
|
|
|
|
|
|
|
} |
34
|
1
|
|
|
|
|
3
|
$res->[1] = \@new_headers; |
35
|
1
|
|
|
|
|
8
|
return $res; |
36
|
|
|
|
|
|
|
} elsif (my $body = $res->[2]) { |
37
|
1
|
50
|
|
|
|
5
|
if ( ref $body eq 'ARRAY' ) { |
38
|
|
|
|
|
|
|
# TODO: look the content-type header. |
39
|
1
|
|
|
|
|
2
|
my $content = ''; |
40
|
1
|
|
|
|
|
4
|
for my $line (@$body) { |
41
|
1
|
50
|
|
|
|
6
|
$content .= $line if length $line; |
42
|
|
|
|
|
|
|
} |
43
|
1
|
|
|
|
|
6
|
$res->[2] = [$self->html_filter($session_id, $content)]; |
44
|
1
|
|
|
|
|
582
|
return $res; |
45
|
|
|
|
|
|
|
} else { # HTTP::Session should not process glob. |
46
|
0
|
|
|
|
|
|
return $res; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
|
return $res; # nop |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |