line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ark::Plugin::Session::State::URI; |
2
|
2
|
|
|
2
|
|
847
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
43
|
|
4
|
2
|
|
|
2
|
|
8
|
use Ark::Plugin 'Session'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has uri_query => ( |
7
|
|
|
|
|
|
|
is => 'rw', |
8
|
|
|
|
|
|
|
lazy => 1, |
9
|
|
|
|
|
|
|
default => sub { |
10
|
|
|
|
|
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
$self->class_config->{query} || 'sid'; |
12
|
|
|
|
|
|
|
}, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has uri_verify_ua => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
lazy => 1, |
18
|
|
|
|
|
|
|
default => sub { |
19
|
|
|
|
|
|
|
my $conf = shift->class_config; |
20
|
|
|
|
|
|
|
exists $conf->{verify_ua} ? $conf->{verify_ua} : 1; |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has uri_rewrite_mobile_only => ( |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
lazy => 1, |
27
|
|
|
|
|
|
|
default => sub { |
28
|
|
|
|
|
|
|
my $conf = shift->class_config; |
29
|
|
|
|
|
|
|
exists $conf->{mobile_only} ? $conf->{mobile_only} : 1; |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has uri_for_override => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
lazy => 1, |
36
|
|
|
|
|
|
|
default => sub { |
37
|
|
|
|
|
|
|
my $conf = shift->class_config; |
38
|
|
|
|
|
|
|
exists $conf->{uri_for_override} ? $conf->{uri_for_override} : 1; |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has uri_remove_marker => ( |
43
|
|
|
|
|
|
|
is => 'rw', |
44
|
|
|
|
|
|
|
default => 0, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has uri_handled => ( |
48
|
|
|
|
|
|
|
is => 'rw', |
49
|
|
|
|
|
|
|
default => 0, |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has uri_session_id => ( |
53
|
|
|
|
|
|
|
is => 'rw', |
54
|
|
|
|
|
|
|
default => '', |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has uri_session_disabled => ( |
58
|
|
|
|
|
|
|
is => 'rw', |
59
|
|
|
|
|
|
|
default => 0, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
around get_session_id => sub { |
63
|
|
|
|
|
|
|
my $next = shift; |
64
|
|
|
|
|
|
|
my $prev = $next->(@_); |
65
|
|
|
|
|
|
|
return $prev if $prev; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my ($self) = @_; |
68
|
|
|
|
|
|
|
my $req = $self->context->request; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return if $self->uri_session_disabled; |
71
|
|
|
|
|
|
|
if ($self->uri_rewrite_mobile_only) { |
72
|
|
|
|
|
|
|
my $agent = $self->context->can('mobile_agent') |
73
|
|
|
|
|
|
|
or $self->log( debug => q[Require MobileAgent plugin for this feature] ); |
74
|
|
|
|
|
|
|
if ($agent && $self->context->mobile_agent->is_non_mobile) { |
75
|
|
|
|
|
|
|
$self->log( |
76
|
|
|
|
|
|
|
warn => q[Disabled uri_session because the user agent is detected as non mobile] |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
$self->uri_session_disabled(1); |
79
|
|
|
|
|
|
|
return; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
unless ($self->uri_remove_marker) { |
84
|
|
|
|
|
|
|
if (my $sid = $req->param( $self->uri_query )) { |
85
|
|
|
|
|
|
|
$self->log( debug => q[Found sessionid "%s" in uri], $sid ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
if ($self->uri_verify_ua) { |
88
|
|
|
|
|
|
|
my $session = $self->get_session_data($sid); |
89
|
|
|
|
|
|
|
if ($session) { |
90
|
|
|
|
|
|
|
if (($session->{__ua} || '') ne $req->user_agent) { |
91
|
|
|
|
|
|
|
$self->log( debug => q[But user_agent is mismatch, ignore this sessionid] ); |
92
|
|
|
|
|
|
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return $self->uri_session_id($sid); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return; |
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
around set_session_id => sub { |
105
|
|
|
|
|
|
|
my $next = shift; |
106
|
|
|
|
|
|
|
my ($self, $sid) = @_; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
unless ($self->uri_session_disabled) { |
109
|
|
|
|
|
|
|
$self->uri_session_id($sid); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$next->(@_); |
113
|
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
around remove_session_id => sub { |
116
|
|
|
|
|
|
|
my $next = shift; |
117
|
|
|
|
|
|
|
my ($self, $sid) = @_; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
unless ($self->uri_session_disabled) { |
120
|
|
|
|
|
|
|
$self->session_id(undef); |
121
|
|
|
|
|
|
|
$self->uri_remove_marker(1); |
122
|
|
|
|
|
|
|
$self->uri_session_id(undef); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$next->(@_); |
126
|
|
|
|
|
|
|
}; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
around finalize_session => sub { |
129
|
|
|
|
|
|
|
my $next = shift; |
130
|
|
|
|
|
|
|
my ($self, $res) = @_; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
unless ($self->uri_session_disabled) { |
133
|
|
|
|
|
|
|
if ($self->uri_verify_ua) { |
134
|
|
|
|
|
|
|
# store ua |
135
|
|
|
|
|
|
|
if ($self->session_updated) { |
136
|
|
|
|
|
|
|
$self->set( __ua => $self->context->request->user_agent ); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$next->(@_); |
142
|
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub BUILD { |
145
|
9
|
|
|
9
|
0
|
327
|
my ($self) = @_; |
146
|
|
|
|
|
|
|
|
147
|
9
|
|
|
|
|
44
|
my $context_class = $self->app->context_class; |
148
|
9
|
|
|
|
|
16
|
my $role = 'Ark::Plugin::Session::State::URI::ExtendContext'; |
149
|
|
|
|
|
|
|
|
150
|
9
|
100
|
|
|
|
31
|
return if $context_class->meta->does_role($role); |
151
|
|
|
|
|
|
|
|
152
|
2
|
|
|
|
|
132
|
$self->ensure_class_loaded($role); |
153
|
2
|
|
|
|
|
20
|
$role->meta->apply( $context_class->meta ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |