line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# proxy::http Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Proxy::Http; |
7
|
1
|
|
|
1
|
|
581
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
569
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
port => [ qw(integer) ], |
20
|
|
|
|
|
|
|
truncate_request => [ qw(integer) ], |
21
|
|
|
|
|
|
|
truncate_response => [ qw(integer) ], |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
attributes_default => { |
24
|
|
|
|
|
|
|
port => 3128, |
25
|
|
|
|
|
|
|
truncate_response => 512, |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
commands => { |
28
|
|
|
|
|
|
|
requests => [ ], |
29
|
|
|
|
|
|
|
requests_responses => [ ], |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
require_modules => { |
32
|
|
|
|
|
|
|
'HTTP::Proxy' => [ ], |
33
|
|
|
|
|
|
|
'HTTP::Proxy::HeaderFilter::simple' => [ ], |
34
|
|
|
|
|
|
|
'LWP::Protocol::connect' => [ ], |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# |
40
|
|
|
|
|
|
|
# XXX: see http://cpansearch.perl.org/src/MIKEM/Net-SSLeay-1.65/examples/https-proxy-snif.pl |
41
|
|
|
|
|
|
|
# XXX: for HTTPS mitm |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
sub requests { |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $proxy = HTTP::Proxy->new( |
47
|
|
|
|
|
|
|
port => $self->port, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$proxy->push_filter( |
51
|
|
|
|
|
|
|
request => HTTP::Proxy::HeaderFilter::simple->new( |
52
|
|
|
|
|
|
|
sub { |
53
|
0
|
|
|
0
|
|
|
my ($self, $headers, $request) = @_; |
54
|
0
|
|
|
|
|
|
my $string = $request->as_string; |
55
|
0
|
0
|
|
|
|
|
if ($self->truncate_request) { |
56
|
0
|
|
|
|
|
|
print substr($string, 0, $self->truncate_request); |
57
|
0
|
|
|
|
|
|
print "\n[..]\n"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
0
|
|
|
|
|
|
print $string; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
}, |
63
|
0
|
|
|
|
|
|
), |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
print "Listening on port: ".$self->port."\n"; |
67
|
0
|
|
|
|
|
|
print "Ready to process browser requests, blocking state...\n"; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $proxy->start; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub requests_responses { |
73
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $proxy = HTTP::Proxy->new( |
76
|
|
|
|
|
|
|
port => $self->port, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$proxy->push_filter( |
80
|
|
|
|
|
|
|
request => HTTP::Proxy::HeaderFilter::simple->new( |
81
|
|
|
|
|
|
|
sub { |
82
|
0
|
|
|
0
|
|
|
my ($proxy, $headers, $request) = @_; |
83
|
0
|
|
|
|
|
|
my $string = $request->as_string; |
84
|
0
|
0
|
|
|
|
|
if ($self->truncate_request) { |
85
|
0
|
|
|
|
|
|
print substr($string, 0, $self->truncate_request); |
86
|
0
|
|
|
|
|
|
print "\n[..]\n"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
0
|
|
|
|
|
|
print $string; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
), |
93
|
|
|
|
|
|
|
response => HTTP::Proxy::HeaderFilter::simple->new( |
94
|
|
|
|
|
|
|
sub { |
95
|
0
|
|
|
0
|
|
|
my ($proxy, $headers, $response) = @_; |
96
|
0
|
|
|
|
|
|
my $string = $response->as_string; |
97
|
0
|
0
|
|
|
|
|
if ($self->truncate_response) { |
98
|
0
|
|
|
|
|
|
print substr($string, 0, $self->truncate_response); |
99
|
0
|
|
|
|
|
|
print "\n[..]\n"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
0
|
|
|
|
|
|
print $string; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
}, |
105
|
0
|
|
|
|
|
|
), |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
print "Listening on port: ".$self->port."\n"; |
109
|
0
|
|
|
|
|
|
print "Ready to process browser requests, blocking state...\n"; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $proxy->start; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |