line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SockJS::Transport::JSONPSend; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
432
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'SockJS::Transport::Base'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
414
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
583
|
use JSON (); |
|
1
|
|
|
|
|
12165
|
|
|
1
|
|
|
|
|
393
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
7
|
|
|
7
|
0
|
19465
|
my $self = shift->SUPER::new(@_); |
12
|
|
|
|
|
|
|
|
13
|
7
|
|
|
|
|
15
|
push @{$self->{allowed_methods}}, 'POST'; |
|
7
|
|
|
|
|
17
|
|
14
|
|
|
|
|
|
|
|
15
|
7
|
|
|
|
|
18
|
return $self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub dispatch_POST { |
19
|
7
|
|
|
7
|
0
|
15
|
my $self = shift; |
20
|
7
|
|
|
|
|
14
|
my ($env, $conn) = @_; |
21
|
|
|
|
|
|
|
|
22
|
7
|
100
|
|
|
|
27
|
return [404, [], ['Not found']] unless $conn->is_connected; |
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
|
|
17
|
my $data = $self->_get_content($env); |
25
|
6
|
100
|
66
|
|
|
31
|
return $data if $data && ref $data eq 'ARRAY'; |
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
|
|
66
|
my $json = JSON->new->utf8->allow_nonref(0); |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
10
|
my $message; |
30
|
4
|
100
|
|
|
|
8
|
eval { $message = $json->decode($data) } || do { |
|
4
|
|
|
|
|
41
|
|
31
|
1
|
|
|
|
|
5
|
return $self->_return_error('Broken JSON encoding.'); |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
3
|
50
|
33
|
|
|
18
|
if ($message && ref $message eq 'ARRAY') { |
35
|
3
|
|
|
|
|
24
|
$conn->fire_event('data', @$message); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return [ |
39
|
3
|
|
|
|
|
24
|
200, |
40
|
|
|
|
|
|
|
[ |
41
|
|
|
|
|
|
|
'Content-Type' => 'text/plain; charset=UTF-8', |
42
|
|
|
|
|
|
|
'Content-Length' => 2, |
43
|
|
|
|
|
|
|
], |
44
|
|
|
|
|
|
|
['ok'] |
45
|
|
|
|
|
|
|
]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _get_content { |
49
|
6
|
|
|
6
|
|
10
|
my $self = shift; |
50
|
6
|
|
|
|
|
12
|
my ($env) = @_; |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
100
|
|
|
26
|
my $content_length = $env->{CONTENT_LENGTH} || 0; |
53
|
6
|
|
|
|
|
22
|
my $rcount = $env->{'psgi.input'}->read(my $chunk, $content_length); |
54
|
|
|
|
|
|
|
|
55
|
6
|
100
|
|
|
|
132
|
return $self->_return_error('System error') |
56
|
|
|
|
|
|
|
unless $rcount == $content_length; |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
9
|
my $d; |
59
|
|
|
|
|
|
|
|
60
|
5
|
100
|
66
|
|
|
45
|
if ( $env->{CONTENT_TYPE} |
61
|
|
|
|
|
|
|
&& $env->{CONTENT_TYPE} eq 'application/x-www-form-urlencoded') |
62
|
|
|
|
|
|
|
{ |
63
|
1
|
|
|
|
|
5
|
$chunk =~ s{\+}{ }g; |
64
|
1
|
|
|
|
|
9
|
($d) = $chunk =~ m/(?:^|&|;)d=([^&;]*)/; |
65
|
1
|
50
|
|
|
|
6
|
$d =~ s/%(..)/chr(hex($1))/eg if defined $d; |
|
0
|
|
|
|
|
0
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
4
|
|
|
|
|
10
|
$d = $chunk; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
5
|
100
|
|
|
|
18
|
return $self->_return_error('Payload expected.') unless length $d; |
72
|
|
|
|
|
|
|
|
73
|
4
|
|
|
|
|
11
|
return $d; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |