line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SockJS::Transport::XHRSend; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
432
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
8
|
use base 'SockJS::Transport::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
405
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
604
|
use JSON (); |
|
1
|
|
|
|
|
11890
|
|
|
1
|
|
|
|
|
270
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
6
|
|
|
6
|
0
|
15738
|
my $self = shift->SUPER::new(@_); |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
|
|
8
|
push @{$self->{allowed_methods}}, 'POST'; |
|
6
|
|
|
|
|
17
|
|
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
|
|
14
|
return $self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub dispatch_POST { |
19
|
6
|
|
|
6
|
0
|
8
|
my $self = shift; |
20
|
6
|
|
|
|
|
13
|
my ($env, $session, $path) = @_; |
21
|
|
|
|
|
|
|
|
22
|
6
|
100
|
|
|
|
16
|
return [404, [], ['Not found']] unless $session->is_connected; |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
|
|
13
|
my $data = $self->_get_content($env); |
25
|
5
|
100
|
100
|
|
|
26
|
return $data if $data && ref $data eq 'ARRAY'; |
26
|
|
|
|
|
|
|
|
27
|
4
|
100
|
|
|
|
11
|
return $self->_return_error('Payload expected.') unless length $data; |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
42
|
my $json = JSON->new->utf8->allow_nonref(0); |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
5
|
my $message; |
32
|
3
|
100
|
|
|
|
7
|
eval { $message = $json->decode($data) } || do { |
|
3
|
|
|
|
|
28
|
|
33
|
1
|
|
|
|
|
4
|
return $self->_return_error('Broken JSON encoding.'); |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
2
|
50
|
33
|
|
|
13
|
if ($message && ref $message eq 'ARRAY') { |
37
|
2
|
|
|
|
|
8
|
$session->fire_event('data', @$message); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
15
|
return [ 204, [ 'Content-Type' => 'text/plain; charset=UTF-8' ], [] ]; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _get_content { |
44
|
5
|
|
|
5
|
|
9
|
my $self = shift; |
45
|
5
|
|
|
|
|
7
|
my ($env) = @_; |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
100
|
|
|
18
|
my $content_length = $env->{CONTENT_LENGTH} || 0; |
48
|
5
|
|
|
|
|
16
|
my $rcount = $env->{'psgi.input'}->read(my $chunk, $content_length); |
49
|
|
|
|
|
|
|
|
50
|
5
|
100
|
|
|
|
103
|
return $self->_return_error('System error') unless $rcount == $content_length; |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
11
|
return $chunk; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |