line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Furl::Cookies; |
2
|
1
|
|
|
1
|
|
26088
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
897
|
use Time::Local; |
|
1
|
|
|
|
|
1954
|
|
|
1
|
|
|
|
|
933
|
|
5
|
|
|
|
|
|
|
#use Data::Dumper::Concise; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $month = { |
10
|
|
|
|
|
|
|
Jan => 1,Feb => 2,Mar => 3,Apr => 4,May => 5,Jun => 6, |
11
|
|
|
|
|
|
|
Jul => 7,Aug => 8,Sep => 9,Oct => 10,Nov => 11,Dec => 12, |
12
|
|
|
|
|
|
|
}; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new{ |
15
|
0
|
|
|
0
|
0
|
|
return bless({COOKIES => {},},shift); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub extract_cookies{ |
19
|
0
|
|
|
0
|
0
|
|
my ($self,$res,$req) = @_; |
20
|
0
|
|
|
|
|
|
$req->uri =~ /^http[s]*:\/\/([^:\/]*)[:]*[0-9]*/; |
21
|
0
|
|
|
|
|
|
my $default_domain = $1; |
22
|
0
|
|
|
|
|
|
for my $cookie (@{$res->headers->{'set-cookie'}}){ |
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#print $cookie . "\n"; |
24
|
0
|
|
|
|
|
|
my ($expires,$domain,$path,$secure,$key,$value); |
25
|
0
|
|
|
|
|
|
for (split(/;/,$cookie)){ |
26
|
0
|
|
|
|
|
|
$_ =~ s/^[\s]*//; |
27
|
0
|
0
|
|
|
|
|
$secure = ($_ =~ /secure/)?1:0; |
28
|
0
|
0
|
|
|
|
|
if($_ =~ /domain/){ |
29
|
0
|
|
|
|
|
|
my @tmp = split(/=/,$_); |
30
|
0
|
|
|
|
|
|
$domain = $tmp[1]; |
31
|
|
|
|
|
|
|
} |
32
|
0
|
0
|
|
|
|
|
if($_ =~ /path/){ |
33
|
0
|
|
|
|
|
|
my @tmp = split(/=/,$_); |
34
|
0
|
|
|
|
|
|
$path = $tmp[1]; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
0
|
|
|
|
|
if($_ =~ /expires/){ |
37
|
0
|
|
|
|
|
|
my @tmp = split(/=/,$_); |
38
|
0
|
|
|
|
|
|
$tmp[1] =~ /([a-zA-Z]*), ([\w]*)-([\w]*)-([\w]*) ([\w]*):([\w]*):([\w]*) GMT/; |
39
|
0
|
|
|
|
|
|
my ($w,$D,$M,$Y,$h,$m,$s) = ($1,$2,$3,$4,$5,$6,$7); |
40
|
0
|
|
|
|
|
|
$expires = timegm($s,$m,$h,$D,$month->{$M}-1,$Y); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
0
|
|
|
|
|
if($_ !~ /expires|path|domain|secure/){ |
43
|
0
|
|
|
|
|
|
my @tmp = split(/=/,$_); |
44
|
0
|
|
|
|
|
|
$key = $tmp[0]; |
45
|
0
|
|
|
|
|
|
$value = $tmp[1]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
|
|
|
|
$domain = $domain?$domain:$default_domain; |
49
|
0
|
0
|
|
|
|
|
$path = $path?$path:'/'; |
50
|
0
|
0
|
|
|
|
|
$expires = $expires?$expires:undef; |
51
|
|
|
|
|
|
|
#next if($expires lt time() && $expires); |
52
|
|
|
|
|
|
|
#next if($default_domain !~ /$domain/ && $domain); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$self->{COOKIES}->{$domain}->{$path}->{$key} = { |
55
|
|
|
|
|
|
|
value => $value, |
56
|
|
|
|
|
|
|
expires => $expires, |
57
|
|
|
|
|
|
|
secure => $secure, |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub add_cookie_header{ |
63
|
0
|
|
|
0
|
0
|
|
my ($self,$req) = @_; |
64
|
0
|
|
|
|
|
|
my $cookies; |
65
|
0
|
|
|
|
|
|
for my $domain (keys %{$self->{COOKIES}}){ |
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
for my $path (keys %{$self->{COOKIES}->{$domain}}){ |
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$req->headers->{cookie} = join('; ', |
68
|
0
|
|
|
|
|
|
map{$_ . '=' . $self->{COOKIES}->{$domain}->{$path}->{$_}->{value}} |
69
|
0
|
|
|
|
|
|
(keys %{$self->{COOKIES}->{$domain}->{$path}})); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |