line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SockJS::Middleware::Cors; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
65965
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
439
|
use parent 'Plack::Middleware'; |
|
1
|
|
|
|
|
287
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
14333
|
use Plack::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
214
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub call { |
11
|
1
|
|
|
1
|
1
|
1234
|
my $self = shift; |
12
|
1
|
|
|
|
|
3
|
my ($env) = @_; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
7
|
my $res = $self->app->(@_); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
return $self->response_cb( |
17
|
|
|
|
|
|
|
$res => sub { |
18
|
1
|
|
|
1
|
|
43
|
my $res = shift; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
6
|
my $h = Plack::Util::headers( $res->[1] ); |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
30
|
my $origin = $env->{HTTP_ORIGIN}; |
23
|
1
|
50
|
|
|
|
4
|
$origin = '' unless defined $origin; |
24
|
|
|
|
|
|
|
|
25
|
1
|
50
|
|
|
|
7
|
my %cors_headers = ( |
26
|
|
|
|
|
|
|
'Access-Control-Allow-Origin' => ( $origin eq '' ) |
27
|
|
|
|
|
|
|
? '*' |
28
|
|
|
|
|
|
|
: $origin, |
29
|
|
|
|
|
|
|
'Access-Control-Allow-Credentials' => 'true' |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
1
|
50
|
|
|
|
5
|
if ( my $request_headers = |
33
|
|
|
|
|
|
|
$env->{HTTP_ACCESS_CONTROL_REQUEST_HEADERS} ) |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
|
|
0
|
$cors_headers{'Access-Control-Allow-Headers'} = |
36
|
|
|
|
|
|
|
$request_headers; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1
|
50
|
|
|
|
3
|
if ( my $allowed_methods = $env->{'sockjs.allowed_methods'} ) { |
40
|
0
|
|
|
|
|
0
|
$cors_headers{'Access-Control-Allow-Methods'} = |
41
|
|
|
|
|
|
|
join( ', ', @$allowed_methods ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
4
|
if ($env->{'sockjs.cacheable'}) { |
45
|
0
|
|
|
|
|
0
|
$cors_headers{'Access-Control-Max-Age'} = '31536000'; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
4
|
foreach my $header ( keys %cors_headers ) { |
49
|
2
|
|
|
|
|
61
|
$h->push( $header => $cors_headers{$header} ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
1
|
|
|
|
|
54
|
); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |