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