line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PocketIO::Transport::XHRMultipart; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
40
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
274
|
|
4
|
6
|
|
|
6
|
|
37
|
use warnings; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
222
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
37
|
use base 'PocketIO::Transport::Base'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
3636
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
0
|
|
|
0
|
1
|
|
my $self = shift->SUPER::new(@_); |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
0
|
|
|
|
$self->{boundary} ||= 'socketio'; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub dispatch { |
17
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
if ($self->{env}->{REQUEST_METHOD} eq 'GET') { |
20
|
0
|
|
|
|
|
|
return $self->_dispatch_stream; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return $self->_dispatch_send; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _dispatch_stream { |
27
|
0
|
|
|
0
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return sub { |
30
|
0
|
|
|
0
|
|
|
my $respond = shift; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $handle = $self->{handle}; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $conn = $self->conn; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $close_cb = sub { $handle->close; $self->client_disconnected($conn); }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$handle->on_eof($close_cb); |
38
|
0
|
|
|
|
|
|
$handle->on_error($close_cb); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $boundary = $self->{boundary}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$conn->on(write => |
43
|
|
|
|
|
|
|
sub { |
44
|
0
|
|
|
|
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
my ($message) = @_; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $string = ''; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$string .= "Content-Type: text/plain\x0a\x0a"; |
50
|
0
|
0
|
|
|
|
|
if ($message eq '') { |
51
|
0
|
|
|
|
|
|
$string .= "-1--$boundary--\x0a"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
|
$string .= "$message\x0a--$boundary\x0a"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$handle->write($string); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$handle->on_heartbeat(sub { $conn->send_heartbeat }); |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$handle->write( |
64
|
|
|
|
|
|
|
join "\x0d\x0a" => 'HTTP/1.1 200 OK', |
65
|
|
|
|
|
|
|
qq{Content-Type: multipart/x-mixed-replace;boundary="$boundary"}, |
66
|
|
|
|
|
|
|
'Access-Control-Allow-Origin: *', |
67
|
|
|
|
|
|
|
'Access-Control-Allow-Credentials: *', |
68
|
|
|
|
|
|
|
'Connection: keep-alive', '', '' |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->client_connected($conn); |
72
|
0
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _dispatch_send { |
76
|
0
|
|
|
0
|
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#my $data = $req->body_parameters->get('data'); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#$self->conn->read($data); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return [200, ['Content-Length' => 1], ['1']]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
__END__ |