line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::Stream::Proxy::HTTPS; |
2
|
3
|
|
|
3
|
|
284758
|
use 5.010001; |
|
3
|
|
|
|
|
23
|
|
3
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
58
|
|
4
|
3
|
|
|
3
|
|
12
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
42
|
|
5
|
3
|
|
|
3
|
|
519
|
use utf8; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
11
|
|
6
|
3
|
|
|
3
|
|
54
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
177
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = 'v2.0.1'; |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
382
|
use IO::Stream::const; |
|
3
|
|
|
|
|
6441
|
|
|
3
|
|
|
|
|
26
|
|
11
|
3
|
|
|
3
|
|
1545
|
use MIME::Base64; |
|
3
|
|
|
|
|
1417
|
|
|
3
|
|
|
|
|
172
|
|
12
|
3
|
|
|
3
|
|
16
|
use Scalar::Util qw( weaken ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
105
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
15
|
use constant HTTP_OK => 200; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1494
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
0
|
|
|
0
|
1
|
|
my ($class, $opt) = @_; |
18
|
|
|
|
|
|
|
croak '{host}+{port} required' |
19
|
|
|
|
|
|
|
if !defined $opt->{host} |
20
|
|
|
|
|
|
|
|| !defined $opt->{port} |
21
|
0
|
0
|
0
|
|
|
|
; |
22
|
|
|
|
|
|
|
croak '{user}+{pass} required' |
23
|
0
|
0
|
0
|
|
|
|
if $opt->{user} xor $opt->{pass}; |
24
|
|
|
|
|
|
|
my $self = bless { |
25
|
|
|
|
|
|
|
host => undef, |
26
|
|
|
|
|
|
|
port => undef, |
27
|
|
|
|
|
|
|
user => undef, |
28
|
|
|
|
|
|
|
pass => undef, |
29
|
0
|
|
|
|
|
|
%{$opt}, |
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
out_buf => q{}, # modified on: OUT |
31
|
|
|
|
|
|
|
out_pos => undef, # modified on: OUT |
32
|
|
|
|
|
|
|
out_bytes => 0, # modified on: OUT |
33
|
|
|
|
|
|
|
in_buf => q{}, # modified on: IN |
34
|
|
|
|
|
|
|
in_bytes => 0, # modified on: IN |
35
|
|
|
|
|
|
|
ip => undef, # modified on: RESOLVED |
36
|
|
|
|
|
|
|
is_eof => undef, # modified on: EOF |
37
|
|
|
|
|
|
|
_want_write => undef, |
38
|
|
|
|
|
|
|
}, $class; |
39
|
0
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub PREPARE { |
43
|
0
|
|
|
0
|
0
|
|
my ($self, $fh, $host, $port) = @_; |
44
|
0
|
0
|
|
|
|
|
croak '{fh} already connected' |
45
|
|
|
|
|
|
|
if !defined $host; |
46
|
0
|
|
|
|
|
|
$self->{out_buf} = "CONNECT ${host}:${port} HTTP/1.0\r\n"; |
47
|
0
|
0
|
|
|
|
|
if (defined $self->{user}) { |
48
|
|
|
|
|
|
|
$self->{out_buf} .= 'Proxy-Authorization: Basic ' |
49
|
0
|
|
|
|
|
|
. encode_base64($self->{user}.q{:}.$self->{pass}, q{}) |
50
|
|
|
|
|
|
|
. "\r\n" |
51
|
|
|
|
|
|
|
; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
$self->{out_buf} .= "\r\n"; |
54
|
0
|
|
|
|
|
|
$self->{_slave}->PREPARE($fh, $self->{host}, $self->{port}); |
55
|
0
|
|
|
|
|
|
$self->{_slave}->WRITE(); |
56
|
0
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub WRITE { |
60
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
61
|
0
|
|
|
|
|
|
$self->{_want_write} = 1; |
62
|
0
|
|
|
|
|
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub EVENT { |
66
|
0
|
|
|
0
|
0
|
|
my ($self, $e, $err) = @_; |
67
|
0
|
|
|
|
|
|
my $m = $self->{_master}; |
68
|
0
|
0
|
|
|
|
|
if ($err) { |
69
|
0
|
|
|
|
|
|
$m->EVENT(0, $err); |
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
|
|
|
|
if ($e & IN) { |
72
|
0
|
0
|
|
|
|
|
if ($self->{in_buf} =~ s{\A(HTTP/\d[.]\d\s(\d+)\s.*?)\r?\n\r?\n}{}xms) { |
73
|
0
|
|
|
|
|
|
my ($reply, $status) = ($1, $2); |
74
|
0
|
0
|
|
|
|
|
if ($status == HTTP_OK) { |
75
|
0
|
|
|
|
|
|
$e = CONNECTED; |
76
|
0
|
0
|
|
|
|
|
if (my $l = length $self->{in_buf}) { |
77
|
0
|
|
|
|
|
|
$e |= IN; |
78
|
0
|
|
|
|
|
|
$m->{in_buf} .= $self->{in_buf}; |
79
|
0
|
|
|
|
|
|
$m->{in_bytes} += $l; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
$m->EVENT($e); |
82
|
0
|
|
|
|
|
|
$self->{_slave}->{_master} = $m; |
83
|
0
|
|
|
|
|
|
weaken($self->{_slave}->{_master}); |
84
|
0
|
|
|
|
|
|
$m->{_slave} = $self->{_slave}; |
85
|
0
|
0
|
|
|
|
|
if ($self->{_want_write}) { |
86
|
0
|
|
|
|
|
|
$self->{_slave}->WRITE(); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else { |
90
|
0
|
|
|
|
|
|
$m->EVENT(0, 'https proxy: '.$reply); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
0
|
0
|
|
|
|
|
if ($e & EOF) { |
95
|
0
|
|
|
|
|
|
$m->{is_eof} = $self->{is_eof}; |
96
|
0
|
|
|
|
|
|
$m->EVENT(0, 'https proxy: unexpected EOF'); |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
103
|
|
|
|
|
|
|
__END__ |