line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::HTTP::Methods; |
2
|
|
|
|
|
|
|
our $VERSION = '6.22'; |
3
|
5
|
|
|
5
|
|
55745
|
use strict; |
|
5
|
|
|
|
|
33
|
|
|
5
|
|
|
|
|
138
|
|
4
|
5
|
|
|
5
|
|
21
|
use warnings; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
114
|
|
5
|
5
|
|
|
5
|
|
3232
|
use URI; |
|
5
|
|
|
|
|
27486
|
|
|
5
|
|
|
|
|
2908
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $CRLF = "\015\012"; # "\r\n" is not portable |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
*_bytes = defined(&utf8::downgrade) ? |
10
|
|
|
|
|
|
|
sub { |
11
|
20
|
50
|
|
20
|
|
61
|
unless (utf8::downgrade($_[0], 1)) { |
12
|
0
|
|
|
|
|
0
|
require Carp; |
13
|
0
|
|
|
|
|
0
|
Carp::croak("Wide character in HTTP request (bytes required)"); |
14
|
|
|
|
|
|
|
} |
15
|
20
|
|
|
|
|
100
|
return $_[0]; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
: |
18
|
|
|
|
|
|
|
sub { |
19
|
|
|
|
|
|
|
return $_[0]; |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
5
|
|
|
5
|
0
|
2977
|
my $class = shift; |
25
|
5
|
100
|
|
|
|
15
|
unshift(@_, "Host") if @_ == 1; |
26
|
5
|
|
|
|
|
16
|
my %cnf = @_; |
27
|
5
|
|
|
|
|
359
|
require Symbol; |
28
|
5
|
|
|
|
|
584
|
my $self = bless Symbol::gensym(), $class; |
29
|
5
|
|
|
|
|
63
|
return $self->http_configure(\%cnf); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub http_configure { |
33
|
8
|
|
|
8
|
0
|
24
|
my($self, $cnf) = @_; |
34
|
|
|
|
|
|
|
|
35
|
8
|
50
|
|
|
|
22
|
die "Listen option not allowed" if $cnf->{Listen}; |
36
|
8
|
|
|
|
|
13
|
my $explicit_host = (exists $cnf->{Host}); |
37
|
8
|
|
|
|
|
13
|
my $host = delete $cnf->{Host}; |
38
|
|
|
|
|
|
|
# All this because $cnf->{PeerAddr} = 0 is actually valid. |
39
|
8
|
|
|
|
|
12
|
my $peer; |
40
|
8
|
|
|
|
|
17
|
for my $key (qw{PeerAddr PeerHost}) { |
41
|
14
|
100
|
66
|
|
|
44
|
next if !defined($cnf->{$key}) || q{} eq $cnf->{$key}; |
42
|
2
|
|
|
|
|
4
|
$peer = $cnf->{$key}; |
43
|
2
|
|
|
|
|
3
|
last; |
44
|
|
|
|
|
|
|
} |
45
|
8
|
100
|
|
|
|
31
|
if (!defined $peer) { |
46
|
6
|
50
|
|
|
|
17
|
die "No Host option provided" unless $host; |
47
|
6
|
|
|
|
|
15
|
$cnf->{PeerAddr} = $peer = $host; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# CONNECTIONS |
51
|
|
|
|
|
|
|
# PREFER: port number from PeerAddr, then PeerPort, then http_default_port |
52
|
8
|
|
|
|
|
41
|
my $peer_uri = URI->new("http://$peer"); |
53
|
8
|
|
66
|
|
|
29897
|
$cnf->{"PeerPort"} = $peer_uri->_port || $cnf->{PeerPort} || $self->http_default_port; |
54
|
8
|
|
|
|
|
176
|
$cnf->{"PeerAddr"} = $peer_uri->host; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# HOST header: |
57
|
|
|
|
|
|
|
# If specified but blank, ignore. |
58
|
|
|
|
|
|
|
# If specified with a value, add the port number |
59
|
|
|
|
|
|
|
# If not specified, set to PeerAddr and port number |
60
|
|
|
|
|
|
|
# ALWAYS: If IPv6 address, use [brackets] (thanks to the URI package) |
61
|
|
|
|
|
|
|
# ALWAYS: omit port number if http_default_port |
62
|
8
|
100
|
100
|
|
|
226
|
if (($host) || (! $explicit_host)) { |
63
|
7
|
100
|
|
|
|
44
|
my $uri = ($explicit_host) ? URI->new("http://$host") : $peer_uri->clone; |
64
|
7
|
100
|
|
|
|
351
|
if (!$uri->_port) { |
65
|
|
|
|
|
|
|
# Always use *our* $self->http_default_port instead of URI's (Covers HTTP, HTTPS) |
66
|
6
|
|
33
|
|
|
112
|
$uri->port( $cnf->{PeerPort} || $self->http_default_port); |
67
|
|
|
|
|
|
|
} |
68
|
7
|
|
|
|
|
372
|
my $host_port = $uri->host_port; # Returns host:port or [ipv6]:port |
69
|
7
|
|
|
|
|
137
|
my $remove = ":" . $self->http_default_port; # we want to remove the default port number |
70
|
7
|
100
|
|
|
|
32
|
if (substr($host_port,0-length($remove)) eq $remove) { |
71
|
5
|
|
|
|
|
12
|
substr($host_port,0-length($remove)) = ""; |
72
|
|
|
|
|
|
|
} |
73
|
7
|
|
|
|
|
30
|
$host = $host_port; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
8
|
|
|
|
|
18
|
$cnf->{Proto} = 'tcp'; |
77
|
|
|
|
|
|
|
|
78
|
8
|
|
|
|
|
12
|
my $keep_alive = delete $cnf->{KeepAlive}; |
79
|
8
|
|
|
|
|
15
|
my $http_version = delete $cnf->{HTTPVersion}; |
80
|
8
|
50
|
|
|
|
22
|
$http_version = "1.1" unless defined $http_version; |
81
|
8
|
|
|
|
|
20
|
my $peer_http_version = delete $cnf->{PeerHTTPVersion}; |
82
|
8
|
100
|
|
|
|
20
|
$peer_http_version = "1.0" unless defined $peer_http_version; |
83
|
8
|
|
|
|
|
11
|
my $send_te = delete $cnf->{SendTE}; |
84
|
8
|
|
|
|
|
14
|
my $max_line_length = delete $cnf->{MaxLineLength}; |
85
|
8
|
100
|
|
|
|
14
|
$max_line_length = 8*1024 unless defined $max_line_length; |
86
|
8
|
|
|
|
|
11
|
my $max_header_lines = delete $cnf->{MaxHeaderLines}; |
87
|
8
|
50
|
|
|
|
14
|
$max_header_lines = 128 unless defined $max_header_lines; |
88
|
|
|
|
|
|
|
|
89
|
8
|
100
|
|
|
|
37
|
return undef unless $self->http_connect($cnf); |
90
|
|
|
|
|
|
|
|
91
|
7
|
|
|
|
|
275379
|
$self->host($host); |
92
|
7
|
|
|
|
|
30
|
$self->keep_alive($keep_alive); |
93
|
7
|
|
|
|
|
29
|
$self->send_te($send_te); |
94
|
7
|
|
|
|
|
34
|
$self->http_version($http_version); |
95
|
7
|
|
|
|
|
31
|
$self->peer_http_version($peer_http_version); |
96
|
7
|
|
|
|
|
30
|
$self->max_line_length($max_line_length); |
97
|
7
|
|
|
|
|
27
|
$self->max_header_lines($max_header_lines); |
98
|
|
|
|
|
|
|
|
99
|
7
|
|
|
|
|
8
|
${*$self}{'http_buf'} = ""; |
|
7
|
|
|
|
|
16
|
|
100
|
|
|
|
|
|
|
|
101
|
7
|
|
|
|
|
46
|
return $self; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub http_default_port { |
105
|
11
|
|
|
11
|
0
|
311
|
80; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# set up property accessors |
109
|
|
|
|
|
|
|
for my $method (qw(host keep_alive send_te max_line_length max_header_lines peer_http_version)) { |
110
|
|
|
|
|
|
|
my $prop_name = "http_" . $method; |
111
|
5
|
|
|
5
|
|
38
|
no strict 'refs'; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
14877
|
|
112
|
|
|
|
|
|
|
*$method = sub { |
113
|
85
|
|
|
85
|
|
2349
|
my $self = shift; |
114
|
85
|
|
|
|
|
89
|
my $old = ${*$self}{$prop_name}; |
|
85
|
|
|
|
|
150
|
|
115
|
85
|
100
|
|
|
|
186
|
${*$self}{$prop_name} = shift if @_; |
|
43
|
|
|
|
|
86
|
|
116
|
85
|
|
|
|
|
149
|
return $old; |
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# we want this one to be a bit smarter |
121
|
|
|
|
|
|
|
sub http_version { |
122
|
8
|
|
|
8
|
0
|
17
|
my $self = shift; |
123
|
8
|
|
|
|
|
11
|
my $old = ${*$self}{'http_version'}; |
|
8
|
|
|
|
|
17
|
|
124
|
8
|
50
|
|
|
|
19
|
if (@_) { |
125
|
8
|
|
|
|
|
16
|
my $v = shift; |
126
|
8
|
50
|
|
|
|
19
|
$v = "1.0" if $v eq "1"; # float |
127
|
8
|
50
|
66
|
|
|
47
|
unless ($v eq "1.0" or $v eq "1.1") { |
128
|
0
|
|
|
|
|
0
|
require Carp; |
129
|
0
|
|
|
|
|
0
|
Carp::croak("Unsupported HTTP version '$v'"); |
130
|
|
|
|
|
|
|
} |
131
|
8
|
|
|
|
|
11
|
${*$self}{'http_version'} = $v; |
|
8
|
|
|
|
|
30
|
|
132
|
|
|
|
|
|
|
} |
133
|
8
|
|
|
|
|
14
|
$old; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub format_request { |
137
|
20
|
|
|
20
|
0
|
32
|
my $self = shift; |
138
|
20
|
|
|
|
|
27
|
my $method = shift; |
139
|
20
|
|
|
|
|
24
|
my $uri = shift; |
140
|
|
|
|
|
|
|
|
141
|
20
|
50
|
|
|
|
57
|
my $content = (@_ % 2) ? pop : ""; |
142
|
|
|
|
|
|
|
|
143
|
20
|
|
|
|
|
39
|
for ($method, $uri) { |
144
|
40
|
|
|
|
|
171
|
require Carp; |
145
|
40
|
50
|
33
|
|
|
186
|
Carp::croak("Bad method or uri") if /\s/ || !length; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
20
|
|
|
|
|
29
|
push(@{${*$self}{'http_request_method'}}, $method); |
|
20
|
|
|
|
|
68
|
|
|
20
|
|
|
|
|
111
|
|
149
|
20
|
|
|
|
|
29
|
my $ver = ${*$self}{'http_version'}; |
|
20
|
|
|
|
|
39
|
|
150
|
20
|
|
50
|
|
|
28
|
my $peer_ver = ${*$self}{'http_peer_http_version'} || "1.0"; |
151
|
|
|
|
|
|
|
|
152
|
20
|
|
|
|
|
30
|
my @h; |
153
|
|
|
|
|
|
|
my @connection; |
154
|
20
|
|
|
|
|
74
|
my %given = (host => 0, "content-length" => 0, "te" => 0); |
155
|
20
|
|
|
|
|
48
|
while (@_) { |
156
|
12
|
|
|
|
|
35
|
my($k, $v) = splice(@_, 0, 2); |
157
|
12
|
|
|
|
|
22
|
my $lc_k = lc($k); |
158
|
12
|
50
|
|
|
|
33
|
if ($lc_k eq "connection") { |
159
|
0
|
|
|
|
|
0
|
$v =~ s/^\s+//; |
160
|
0
|
|
|
|
|
0
|
$v =~ s/\s+$//; |
161
|
0
|
|
|
|
|
0
|
push(@connection, split(/\s*,\s*/, $v)); |
162
|
0
|
|
|
|
|
0
|
next; |
163
|
|
|
|
|
|
|
} |
164
|
12
|
50
|
|
|
|
36
|
if (exists $given{$lc_k}) { |
165
|
0
|
|
|
|
|
0
|
$given{$lc_k}++; |
166
|
|
|
|
|
|
|
} |
167
|
12
|
|
|
|
|
62
|
push(@h, "$k: $v"); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
20
|
50
|
33
|
|
|
49
|
if (length($content) && !$given{'content-length'}) { |
171
|
0
|
|
|
|
|
0
|
push(@h, "Content-Length: " . length($content)); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
20
|
|
|
|
|
27
|
my @h2; |
175
|
20
|
50
|
33
|
|
|
55
|
if ($given{te}) { |
|
|
50
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
0
|
push(@connection, "TE") unless grep lc($_) eq "te", @connection; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
elsif ($self->send_te && gunzip_ok()) { |
179
|
|
|
|
|
|
|
# gzip is less wanted since the IO::Uncompress::Gunzip interface for |
180
|
|
|
|
|
|
|
# it does not really allow chunked decoding to take place easily. |
181
|
0
|
|
|
|
|
0
|
push(@h2, "TE: deflate,gzip;q=0.3"); |
182
|
0
|
|
|
|
|
0
|
push(@connection, "TE"); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
20
|
50
|
|
|
|
46
|
unless (grep lc($_) eq "close", @connection) { |
186
|
20
|
100
|
|
|
|
58
|
if ($self->keep_alive) { |
187
|
12
|
100
|
|
|
|
28
|
if ($peer_ver eq "1.0") { |
188
|
|
|
|
|
|
|
# from looking at Netscape's headers |
189
|
4
|
|
|
|
|
6
|
push(@h2, "Keep-Alive: 300"); |
190
|
4
|
|
|
|
|
9
|
unshift(@connection, "Keep-Alive"); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
else { |
194
|
8
|
100
|
|
|
|
20
|
push(@connection, "close") if $ver ge "1.1"; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
} |
197
|
20
|
100
|
|
|
|
59
|
push(@h2, "Connection: " . join(", ", @connection)) if @connection; |
198
|
20
|
50
|
|
|
|
46
|
unless ($given{host}) { |
199
|
20
|
|
|
|
|
23
|
my $h = ${*$self}{'http_host'}; |
|
20
|
|
|
|
|
41
|
|
200
|
20
|
100
|
|
|
|
54
|
push(@h2, "Host: $h") if $h; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
20
|
|
|
|
|
85
|
return _bytes(join($CRLF, "$method $uri HTTP/$ver", @h2, @h, "", $content)); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub write_request { |
208
|
20
|
|
|
20
|
0
|
14750
|
my $self = shift; |
209
|
20
|
|
|
|
|
63
|
$self->print($self->format_request(@_)); |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub format_chunk { |
213
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
214
|
0
|
0
|
0
|
|
|
0
|
return $_[0] unless defined($_[0]) && length($_[0]); |
215
|
0
|
|
|
|
|
0
|
return _bytes(sprintf("%x", length($_[0])) . $CRLF . $_[0] . $CRLF); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub write_chunk { |
219
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
220
|
0
|
0
|
0
|
|
|
0
|
return 1 unless defined($_[0]) && length($_[0]); |
221
|
0
|
|
|
|
|
0
|
$self->print(_bytes(sprintf("%x", length($_[0])) . $CRLF . $_[0] . $CRLF)); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub format_chunk_eof { |
225
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
226
|
0
|
|
|
|
|
0
|
my @h; |
227
|
0
|
|
|
|
|
0
|
while (@_) { |
228
|
0
|
|
|
|
|
0
|
push(@h, sprintf "%s: %s$CRLF", splice(@_, 0, 2)); |
229
|
|
|
|
|
|
|
} |
230
|
0
|
|
|
|
|
0
|
return _bytes(join("", "0$CRLF", @h, $CRLF)); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub write_chunk_eof { |
234
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
235
|
0
|
|
|
|
|
0
|
$self->print($self->format_chunk_eof(@_)); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub my_read { |
240
|
1280
|
50
|
|
1280
|
0
|
1949
|
die if @_ > 3; |
241
|
1280
|
|
|
|
|
1342
|
my $self = shift; |
242
|
1280
|
|
|
|
|
1361
|
my $len = $_[1]; |
243
|
1280
|
|
|
|
|
1375
|
for (${*$self}{'http_buf'}) { |
|
1280
|
|
|
|
|
2281
|
|
244
|
1280
|
100
|
|
|
|
1734
|
if (length) { |
245
|
62
|
|
|
|
|
86
|
$_[0] = substr($_, 0, $len, ""); |
246
|
62
|
|
|
|
|
177
|
return length($_[0]); |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
else { |
249
|
1218
|
50
|
|
|
|
1654
|
die "read timeout" unless $self->can_read; |
250
|
1218
|
|
|
|
|
8984
|
return $self->sysread($_[0], $len); |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub my_readline { |
257
|
153
|
|
|
153
|
0
|
173
|
my $self = shift; |
258
|
153
|
|
|
|
|
173
|
my $what = shift; |
259
|
153
|
|
|
|
|
151
|
for (${*$self}{'http_buf'}) { |
|
153
|
|
|
|
|
303
|
|
260
|
153
|
|
|
|
|
150
|
my $max_line_length = ${*$self}{'http_max_line_length'}; |
|
153
|
|
|
|
|
232
|
|
261
|
153
|
|
|
|
|
174
|
my $pos; |
262
|
153
|
|
|
|
|
191
|
while (1) { |
263
|
|
|
|
|
|
|
# find line ending |
264
|
634
|
|
|
|
|
728
|
$pos = index($_, "\012"); |
265
|
634
|
100
|
|
|
|
844
|
last if $pos >= 0; |
266
|
481
|
50
|
33
|
|
|
1064
|
die "$what line too long (limit is $max_line_length)" |
267
|
|
|
|
|
|
|
if $max_line_length && length($_) > $max_line_length; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# need to read more data to find a line ending |
270
|
481
|
|
|
|
|
498
|
my $new_bytes = 0; |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
READ: |
273
|
|
|
|
|
|
|
{ # wait until bytes start arriving |
274
|
481
|
50
|
|
|
|
479
|
$self->can_read |
|
481
|
|
|
|
|
660
|
|
275
|
|
|
|
|
|
|
or die "read timeout"; |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
# consume all incoming bytes |
278
|
481
|
|
|
|
|
879
|
my $bytes_read = $self->sysread($_, 1024, length); |
279
|
481
|
50
|
0
|
|
|
5233
|
if(defined $bytes_read) { |
|
|
0
|
0
|
|
|
|
|
280
|
481
|
|
|
|
|
497
|
$new_bytes += $bytes_read; |
281
|
|
|
|
|
|
|
} |
282
|
1
|
|
|
1
|
|
430
|
elsif($!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK}) { |
|
1
|
|
|
|
|
1102
|
|
|
1
|
|
|
|
|
7
|
|
283
|
0
|
|
|
|
|
0
|
redo READ; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
else { |
286
|
|
|
|
|
|
|
# if we have already accumulated some data let's at |
287
|
|
|
|
|
|
|
# least return that as a line |
288
|
0
|
0
|
|
|
|
0
|
length or die "$what read failed: $!"; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
# no line-ending, no new bytes |
292
|
481
|
0
|
|
|
|
722
|
return length($_) ? substr($_, 0, length($_), "") : undef |
|
|
50
|
|
|
|
|
|
293
|
|
|
|
|
|
|
if $new_bytes==0; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
} |
296
|
153
|
50
|
33
|
|
|
407
|
die "$what line too long ($pos; limit is $max_line_length)" |
297
|
|
|
|
|
|
|
if $max_line_length && $pos > $max_line_length; |
298
|
|
|
|
|
|
|
|
299
|
153
|
|
|
|
|
309
|
my $line = substr($_, 0, $pos+1, ""); |
300
|
153
|
50
|
|
|
|
650
|
$line =~ s/(\015?\012)\z// || die "Assert"; |
301
|
153
|
100
|
|
|
|
508
|
return wantarray ? ($line, $1) : $line; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
sub can_read { |
307
|
1696
|
|
|
1696
|
0
|
1792
|
my $self = shift; |
308
|
1696
|
100
|
|
|
|
3108
|
return 1 unless defined(fileno($self)); |
309
|
1196
|
100
|
100
|
|
|
10188
|
return 1 if $self->isa('IO::Socket::SSL') && $self->pending; |
310
|
364
|
0
|
33
|
|
|
1058
|
return 1 if $self->isa('Net::SSL') && $self->can('pending') && $self->pending; |
|
|
|
33
|
|
|
|
|
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
# With no timeout, wait forever. An explicit timeout of 0 can be |
313
|
|
|
|
|
|
|
# used to just check if the socket is readable without waiting. |
314
|
364
|
50
|
50
|
|
|
544
|
my $timeout = @_ ? shift : (${*$self}{io_socket_timeout} || undef); |
315
|
|
|
|
|
|
|
|
316
|
364
|
|
|
|
|
476
|
my $fbits = ''; |
317
|
364
|
|
|
|
|
825
|
vec($fbits, fileno($self), 1) = 1; |
318
|
|
|
|
|
|
|
SELECT: |
319
|
|
|
|
|
|
|
{ |
320
|
364
|
|
|
|
|
672
|
my $before; |
|
364
|
|
|
|
|
438
|
|
321
|
364
|
50
|
|
|
|
530
|
$before = time if $timeout; |
322
|
364
|
|
|
|
|
59213
|
my $nfound = select($fbits, undef, undef, $timeout); |
323
|
364
|
50
|
|
|
|
889
|
if ($nfound < 0) { |
324
|
0
|
0
|
0
|
|
|
0
|
if ($!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK}) { |
|
|
|
0
|
|
|
|
|
325
|
|
|
|
|
|
|
# don't really think EAGAIN/EWOULDBLOCK can happen here |
326
|
0
|
0
|
|
|
|
0
|
if ($timeout) { |
327
|
0
|
|
|
|
|
0
|
$timeout -= time - $before; |
328
|
0
|
0
|
|
|
|
0
|
$timeout = 0 if $timeout < 0; |
329
|
|
|
|
|
|
|
} |
330
|
0
|
|
|
|
|
0
|
redo SELECT; |
331
|
|
|
|
|
|
|
} |
332
|
0
|
|
|
|
|
0
|
die "select failed: $!"; |
333
|
|
|
|
|
|
|
} |
334
|
364
|
|
|
|
|
1061
|
return $nfound > 0; |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
sub _rbuf { |
340
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
341
|
0
|
0
|
|
|
|
0
|
if (@_) { |
342
|
0
|
|
|
|
|
0
|
for (${*$self}{'http_buf'}) { |
|
0
|
|
|
|
|
0
|
|
343
|
0
|
|
|
|
|
0
|
my $old; |
344
|
0
|
0
|
|
|
|
0
|
$old = $_ if defined wantarray; |
345
|
0
|
|
|
|
|
0
|
$_ = shift; |
346
|
0
|
|
|
|
|
0
|
return $old; |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
else { |
350
|
0
|
|
|
|
|
0
|
return ${*$self}{'http_buf'}; |
|
0
|
|
|
|
|
0
|
|
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
sub _rbuf_length { |
355
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
356
|
0
|
|
|
|
|
0
|
return length ${*$self}{'http_buf'}; |
|
0
|
|
|
|
|
0
|
|
357
|
|
|
|
|
|
|
} |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
sub _read_header_lines { |
361
|
21
|
|
|
21
|
|
33
|
my $self = shift; |
362
|
21
|
|
|
|
|
24
|
my $junk_out = shift; |
363
|
|
|
|
|
|
|
|
364
|
21
|
|
|
|
|
58
|
my @headers; |
365
|
21
|
|
|
|
|
27
|
my $line_count = 0; |
366
|
21
|
|
|
|
|
25
|
my $max_header_lines = ${*$self}{'http_max_header_lines'}; |
|
21
|
|
|
|
|
36
|
|
367
|
21
|
|
|
|
|
45
|
while (my $line = my_readline($self, 'Header')) { |
368
|
92
|
100
|
33
|
|
|
314
|
if ($line =~ /^(\S+?)\s*:\s*(.*)/s) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
369
|
90
|
|
|
|
|
261
|
push(@headers, $1, $2); |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
elsif (@headers && $line =~ s/^\s+//) { |
372
|
0
|
|
|
|
|
0
|
$headers[-1] .= " " . $line; |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
elsif ($junk_out) { |
375
|
1
|
|
|
|
|
3
|
push(@$junk_out, $line); |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
else { |
378
|
1
|
|
|
|
|
8
|
die "Bad header: '$line'\n"; |
379
|
|
|
|
|
|
|
} |
380
|
91
|
50
|
|
|
|
145
|
if ($max_header_lines) { |
381
|
91
|
|
|
|
|
95
|
$line_count++; |
382
|
91
|
50
|
|
|
|
201
|
if ($line_count >= $max_header_lines) { |
383
|
0
|
|
|
|
|
0
|
die "Too many header lines (limit is $max_header_lines)"; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
} |
387
|
20
|
|
|
|
|
81
|
return @headers; |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
sub read_response_headers { |
392
|
20
|
|
|
20
|
0
|
2750
|
my($self, %opt) = @_; |
393
|
20
|
|
|
|
|
29
|
my $laxed = $opt{laxed}; |
394
|
|
|
|
|
|
|
|
395
|
20
|
|
|
|
|
42
|
my($status, $eol) = my_readline($self, 'Status'); |
396
|
20
|
50
|
|
|
|
44
|
unless (defined $status) { |
397
|
0
|
|
|
|
|
0
|
die "Server closed connection without sending any data back"; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
20
|
|
|
|
|
103
|
my($peer_ver, $code, $message) = split(/\s+/, $status, 3); |
401
|
20
|
100
|
66
|
|
|
161
|
if (!$peer_ver || $peer_ver !~ s,^HTTP/,, || $code !~ /^[1-5]\d\d$/) { |
|
|
|
66
|
|
|
|
|
402
|
2
|
100
|
|
|
|
12
|
die "Bad response status line: '$status'" unless $laxed; |
403
|
|
|
|
|
|
|
# assume HTTP/0.9 |
404
|
1
|
|
|
|
|
1
|
${*$self}{'http_peer_http_version'} = "0.9"; |
|
1
|
|
|
|
|
3
|
|
405
|
1
|
|
|
|
|
2
|
${*$self}{'http_status'} = "200"; |
|
1
|
|
|
|
|
2
|
|
406
|
1
|
|
50
|
|
|
3
|
substr(${*$self}{'http_buf'}, 0, 0) = $status . ($eol || ""); |
|
1
|
|
|
|
|
3
|
|
407
|
1
|
50
|
|
|
|
3
|
return 200 unless wantarray; |
408
|
1
|
|
|
|
|
3
|
return (200, "Assumed OK"); |
409
|
|
|
|
|
|
|
}; |
410
|
|
|
|
|
|
|
|
411
|
18
|
|
|
|
|
41
|
${*$self}{'http_peer_http_version'} = $peer_ver; |
|
18
|
|
|
|
|
357
|
|
412
|
18
|
|
|
|
|
26
|
${*$self}{'http_status'} = $code; |
|
18
|
|
|
|
|
35
|
|
413
|
|
|
|
|
|
|
|
414
|
18
|
|
|
|
|
26
|
my $junk_out; |
415
|
18
|
100
|
|
|
|
34
|
if ($laxed) { |
416
|
1
|
|
50
|
|
|
5
|
$junk_out = $opt{junk_out} || []; |
417
|
|
|
|
|
|
|
} |
418
|
18
|
|
|
|
|
78
|
my @headers = $self->_read_header_lines($junk_out); |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
# pick out headers that read_entity_body might need |
421
|
17
|
|
|
|
|
28
|
my @te; |
422
|
|
|
|
|
|
|
my $content_length; |
423
|
17
|
|
|
|
|
55
|
for (my $i = 0; $i < @headers; $i += 2) { |
424
|
86
|
|
|
|
|
125
|
my $h = lc($headers[$i]); |
425
|
86
|
100
|
|
|
|
186
|
if ($h eq 'transfer-encoding') { |
|
|
100
|
|
|
|
|
|
426
|
4
|
|
|
|
|
5
|
my $te = $headers[$i+1]; |
427
|
4
|
|
|
|
|
7
|
$te =~ s/^\s+//; |
428
|
4
|
|
|
|
|
7
|
$te =~ s/\s+$//; |
429
|
4
|
50
|
|
|
|
12
|
push(@te, $te) if length($te); |
430
|
|
|
|
|
|
|
} |
431
|
|
|
|
|
|
|
elsif ($h eq 'content-length') { |
432
|
|
|
|
|
|
|
# ignore bogus and overflow values |
433
|
12
|
50
|
|
|
|
51
|
if ($headers[$i+1] =~ /^\s*(\d{1,15})(?:\s|$)/) { |
434
|
12
|
|
|
|
|
50
|
$content_length = $1; |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
} |
437
|
|
|
|
|
|
|
} |
438
|
17
|
|
|
|
|
38
|
${*$self}{'http_te'} = join(",", @te); |
|
17
|
|
|
|
|
36
|
|
439
|
17
|
|
|
|
|
27
|
${*$self}{'http_content_length'} = $content_length; |
|
17
|
|
|
|
|
28
|
|
440
|
17
|
|
|
|
|
23
|
${*$self}{'http_first_body'}++; |
|
17
|
|
|
|
|
35
|
|
441
|
17
|
|
|
|
|
20
|
delete ${*$self}{'http_trailers'}; |
|
17
|
|
|
|
|
30
|
|
442
|
17
|
50
|
|
|
|
58
|
return $code unless wantarray; |
443
|
17
|
|
|
|
|
138
|
return ($code, $message, @headers); |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
sub read_entity_body { |
448
|
1295
|
|
|
1295
|
0
|
6780
|
my $self = shift; |
449
|
1295
|
|
|
|
|
1528
|
my $buf_ref = \$_[0]; |
450
|
1295
|
|
|
|
|
1415
|
my $size = $_[1]; |
451
|
1295
|
50
|
|
|
|
1898
|
die "Offset not supported yet" if $_[2]; |
452
|
|
|
|
|
|
|
|
453
|
1295
|
|
|
|
|
1590
|
my $chunked; |
454
|
|
|
|
|
|
|
my $bytes; |
455
|
|
|
|
|
|
|
|
456
|
1295
|
100
|
|
|
|
1325
|
if (${*$self}{'http_first_body'}) { |
|
1295
|
|
|
|
|
2264
|
|
457
|
17
|
|
|
|
|
21
|
${*$self}{'http_first_body'} = 0; |
|
17
|
|
|
|
|
25
|
|
458
|
17
|
|
|
|
|
22
|
delete ${*$self}{'http_chunked'}; |
|
17
|
|
|
|
|
27
|
|
459
|
17
|
|
|
|
|
20
|
delete ${*$self}{'http_bytes'}; |
|
17
|
|
|
|
|
29
|
|
460
|
17
|
|
|
|
|
20
|
my $method = shift(@{${*$self}{'http_request_method'}}); |
|
17
|
|
|
|
|
17
|
|
|
17
|
|
|
|
|
41
|
|
461
|
17
|
|
|
|
|
22
|
my $status = ${*$self}{'http_status'}; |
|
17
|
|
|
|
|
27
|
|
462
|
17
|
100
|
|
|
|
35
|
if ($method eq "HEAD") { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
463
|
|
|
|
|
|
|
# this response is always empty regardless of other headers |
464
|
1
|
|
|
|
|
2
|
$bytes = 0; |
465
|
|
|
|
|
|
|
} |
466
|
16
|
|
|
|
|
37
|
elsif (my $te = ${*$self}{'http_te'}) { |
467
|
3
|
|
|
|
|
10
|
my @te = split(/\s*,\s*/, lc($te)); |
468
|
3
|
50
|
|
|
|
6
|
die "Chunked must be last Transfer-Encoding '$te'" |
469
|
|
|
|
|
|
|
unless pop(@te) eq "chunked"; |
470
|
3
|
|
66
|
|
|
13
|
pop(@te) while @te && $te[-1] eq "chunked"; # ignore repeated chunked spec |
471
|
|
|
|
|
|
|
|
472
|
3
|
|
|
|
|
6
|
for (@te) { |
473
|
0
|
0
|
0
|
|
|
0
|
if ($_ eq "deflate" && inflate_ok()) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
474
|
|
|
|
|
|
|
#require Compress::Raw::Zlib; |
475
|
0
|
|
|
|
|
0
|
my ($i, $status) = Compress::Raw::Zlib::Inflate->new(); |
476
|
0
|
0
|
|
|
|
0
|
die "Can't make inflator: $status" unless $i; |
477
|
0
|
|
|
0
|
|
0
|
$_ = sub { my $out; $i->inflate($_[0], \$out); $out } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
478
|
0
|
|
|
|
|
0
|
} |
479
|
|
|
|
|
|
|
elsif ($_ eq "gzip" && gunzip_ok()) { |
480
|
|
|
|
|
|
|
#require IO::Uncompress::Gunzip; |
481
|
0
|
|
|
|
|
0
|
my @buf; |
482
|
|
|
|
|
|
|
$_ = sub { |
483
|
0
|
|
|
0
|
|
0
|
push(@buf, $_[0]); |
484
|
0
|
0
|
|
|
|
0
|
return "" unless $_[1]; |
485
|
0
|
|
|
|
|
0
|
my $input = join("", @buf); |
486
|
0
|
|
|
|
|
0
|
my $output; |
487
|
0
|
0
|
|
|
|
0
|
IO::Uncompress::Gunzip::gunzip(\$input, \$output, Transparent => 0) |
488
|
|
|
|
|
|
|
or die "Can't gunzip content: $IO::Uncompress::Gunzip::GunzipError"; |
489
|
0
|
|
|
|
|
0
|
return \$output; |
490
|
0
|
|
|
|
|
0
|
}; |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
elsif ($_ eq "identity") { |
493
|
0
|
|
|
0
|
|
0
|
$_ = sub { $_[0] }; |
|
0
|
|
|
|
|
0
|
|
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
else { |
496
|
0
|
|
|
|
|
0
|
die "Can't handle transfer encoding '$te'"; |
497
|
|
|
|
|
|
|
} |
498
|
|
|
|
|
|
|
} |
499
|
|
|
|
|
|
|
|
500
|
3
|
|
|
|
|
4
|
@te = reverse(@te); |
501
|
|
|
|
|
|
|
|
502
|
3
|
50
|
|
|
|
5
|
${*$self}{'http_te2'} = @te ? \@te : ""; |
|
3
|
|
|
|
|
5
|
|
503
|
3
|
|
|
|
|
5
|
$chunked = -1; |
504
|
|
|
|
|
|
|
} |
505
|
13
|
|
|
|
|
47
|
elsif (defined(my $content_length = ${*$self}{'http_content_length'})) { |
506
|
11
|
|
|
|
|
24
|
$bytes = $content_length; |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
elsif ($status =~ /^(?:1|[23]04)/) { |
509
|
|
|
|
|
|
|
# RFC 2616 says that these responses should always be empty |
510
|
|
|
|
|
|
|
# but that does not appear to be true in practice [RT#17907] |
511
|
0
|
|
|
|
|
0
|
$bytes = 0; |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
else { |
514
|
|
|
|
|
|
|
# XXX Multi-Part types are self delimiting, but RFC 2616 says we |
515
|
|
|
|
|
|
|
# only has to deal with 'multipart/byteranges' |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
# Read until EOF |
518
|
|
|
|
|
|
|
} |
519
|
|
|
|
|
|
|
} |
520
|
|
|
|
|
|
|
else { |
521
|
1278
|
|
|
|
|
1312
|
$chunked = ${*$self}{'http_chunked'}; |
|
1278
|
|
|
|
|
1768
|
|
522
|
1278
|
|
|
|
|
1489
|
$bytes = ${*$self}{'http_bytes'}; |
|
1278
|
|
|
|
|
1765
|
|
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
|
525
|
1295
|
100
|
|
|
|
2204
|
if (defined $chunked) { |
|
|
100
|
|
|
|
|
|
526
|
|
|
|
|
|
|
# The state encoded in $chunked is: |
527
|
|
|
|
|
|
|
# $chunked == 0: read CRLF after chunk, then chunk header |
528
|
|
|
|
|
|
|
# $chunked == -1: read chunk header |
529
|
|
|
|
|
|
|
# $chunked > 0: bytes left in current chunk to read |
530
|
|
|
|
|
|
|
|
531
|
18
|
100
|
|
|
|
25
|
if ($chunked <= 0) { |
532
|
12
|
|
|
|
|
18
|
my $line = my_readline($self, 'Entity body'); |
533
|
12
|
100
|
|
|
|
35
|
if ($chunked == 0) { |
534
|
9
|
50
|
33
|
|
|
31
|
die "Missing newline after chunk data: '$line'" |
535
|
|
|
|
|
|
|
if !defined($line) || $line ne ""; |
536
|
9
|
|
|
|
|
16
|
$line = my_readline($self, 'Entity body'); |
537
|
|
|
|
|
|
|
} |
538
|
12
|
50
|
|
|
|
22
|
die "EOF when chunk header expected" unless defined($line); |
539
|
12
|
|
|
|
|
13
|
my $chunk_len = $line; |
540
|
12
|
|
|
|
|
20
|
$chunk_len =~ s/;.*//; # ignore potential chunk parameters |
541
|
12
|
50
|
|
|
|
34
|
unless ($chunk_len =~ /^([\da-fA-F]+)\s*$/) { |
542
|
0
|
|
|
|
|
0
|
die "Bad chunk-size in HTTP response: $line"; |
543
|
|
|
|
|
|
|
} |
544
|
12
|
|
|
|
|
22
|
$chunked = hex($1); |
545
|
12
|
|
|
|
|
12
|
${*$self}{'http_chunked'} = $chunked; |
|
12
|
|
|
|
|
23
|
|
546
|
12
|
100
|
|
|
|
24
|
if ($chunked == 0) { |
547
|
3
|
|
|
|
|
6
|
${*$self}{'http_trailers'} = [$self->_read_header_lines]; |
|
3
|
|
|
|
|
7
|
|
548
|
3
|
|
|
|
|
6
|
$$buf_ref = ""; |
549
|
|
|
|
|
|
|
|
550
|
3
|
|
|
|
|
4
|
my $n = 0; |
551
|
3
|
50
|
|
|
|
3
|
if (my $transforms = delete ${*$self}{'http_te2'}) { |
|
3
|
|
|
|
|
8
|
|
552
|
0
|
|
|
|
|
0
|
for (@$transforms) { |
553
|
0
|
|
|
|
|
0
|
$$buf_ref = &$_($$buf_ref, 1); |
554
|
|
|
|
|
|
|
} |
555
|
0
|
|
|
|
|
0
|
$n = length($$buf_ref); |
556
|
|
|
|
|
|
|
} |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
# in case somebody tries to read more, make sure we continue |
559
|
|
|
|
|
|
|
# to return EOF |
560
|
3
|
|
|
|
|
3
|
delete ${*$self}{'http_chunked'}; |
|
3
|
|
|
|
|
4
|
|
561
|
3
|
|
|
|
|
3
|
${*$self}{'http_bytes'} = 0; |
|
3
|
|
|
|
|
6
|
|
562
|
|
|
|
|
|
|
|
563
|
3
|
|
|
|
|
6
|
return $n; |
564
|
|
|
|
|
|
|
} |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
|
567
|
15
|
|
|
|
|
14
|
my $n = $chunked; |
568
|
15
|
50
|
33
|
|
|
37
|
$n = $size if $size && $size < $n; |
569
|
15
|
|
|
|
|
25
|
$n = my_read($self, $$buf_ref, $n); |
570
|
15
|
50
|
|
|
|
170
|
return undef unless defined $n; |
571
|
|
|
|
|
|
|
|
572
|
15
|
|
|
|
|
17
|
${*$self}{'http_chunked'} = $chunked - $n; |
|
15
|
|
|
|
|
20
|
|
573
|
|
|
|
|
|
|
|
574
|
15
|
50
|
|
|
|
26
|
if ($n > 0) { |
575
|
15
|
50
|
|
|
|
15
|
if (my $transforms = ${*$self}{'http_te2'}) { |
|
15
|
|
|
|
|
30
|
|
576
|
0
|
|
|
|
|
0
|
for (@$transforms) { |
577
|
0
|
|
|
|
|
0
|
$$buf_ref = &$_($$buf_ref, 0); |
578
|
|
|
|
|
|
|
} |
579
|
0
|
|
|
|
|
0
|
$n = length($$buf_ref); |
580
|
0
|
0
|
|
|
|
0
|
$n = -1 if $n == 0; |
581
|
|
|
|
|
|
|
} |
582
|
|
|
|
|
|
|
} |
583
|
15
|
|
|
|
|
29
|
return $n; |
584
|
|
|
|
|
|
|
} |
585
|
|
|
|
|
|
|
elsif (defined $bytes) { |
586
|
1272
|
100
|
|
|
|
1794
|
unless ($bytes) { |
587
|
12
|
|
|
|
|
21
|
$$buf_ref = ""; |
588
|
12
|
|
|
|
|
30
|
return 0; |
589
|
|
|
|
|
|
|
} |
590
|
1260
|
|
|
|
|
1282
|
my $n = $bytes; |
591
|
1260
|
100
|
66
|
|
|
2944
|
$n = $size if $size && $size < $n; |
592
|
1260
|
|
|
|
|
1699
|
$n = my_read($self, $$buf_ref, $n); |
593
|
1260
|
100
|
|
|
|
24120
|
${*$self}{'http_bytes'} = defined $n ? $bytes - $n : $bytes; |
|
1260
|
|
|
|
|
2204
|
|
594
|
1260
|
|
|
|
|
2304
|
return $n; |
595
|
|
|
|
|
|
|
} |
596
|
|
|
|
|
|
|
else { |
597
|
|
|
|
|
|
|
# read until eof |
598
|
5
|
|
50
|
|
|
8
|
$size ||= 8*1024; |
599
|
5
|
|
|
|
|
9
|
return my_read($self, $$buf_ref, $size); |
600
|
|
|
|
|
|
|
} |
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
sub get_trailers { |
604
|
13
|
|
|
13
|
0
|
107
|
my $self = shift; |
605
|
13
|
100
|
|
|
|
14
|
@{${*$self}{'http_trailers'} || []}; |
|
13
|
|
|
|
|
13
|
|
|
13
|
|
|
|
|
63
|
|
606
|
|
|
|
|
|
|
} |
607
|
|
|
|
|
|
|
|
608
|
0
|
|
|
|
|
0
|
BEGIN { |
609
|
5
|
|
|
5
|
|
2109
|
my $gunzip_ok; |
610
|
5
|
|
|
|
|
172
|
my $inflate_ok; |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
sub gunzip_ok { |
613
|
0
|
0
|
|
0
|
0
|
0
|
return $gunzip_ok if defined $gunzip_ok; |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
# Try to load IO::Uncompress::Gunzip. |
616
|
0
|
|
|
|
|
0
|
local $@; |
617
|
0
|
|
|
|
|
0
|
local $SIG{__DIE__}; |
618
|
0
|
|
|
|
|
0
|
$gunzip_ok = 0; |
619
|
|
|
|
|
|
|
|
620
|
0
|
|
|
|
|
0
|
eval { |
621
|
0
|
|
|
|
|
0
|
require IO::Uncompress::Gunzip; |
622
|
0
|
|
|
|
|
0
|
$gunzip_ok++; |
623
|
|
|
|
|
|
|
}; |
624
|
|
|
|
|
|
|
|
625
|
0
|
|
|
|
|
0
|
return $gunzip_ok; |
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
sub inflate_ok { |
629
|
0
|
0
|
|
0
|
0
|
0
|
return $inflate_ok if defined $inflate_ok; |
630
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
# Try to load Compress::Raw::Zlib. |
632
|
0
|
|
|
|
|
0
|
local $@; |
633
|
0
|
|
|
|
|
0
|
local $SIG{__DIE__}; |
634
|
0
|
|
|
|
|
0
|
$inflate_ok = 0; |
635
|
|
|
|
|
|
|
|
636
|
0
|
|
|
|
|
0
|
eval { |
637
|
0
|
|
|
|
|
0
|
require Compress::Raw::Zlib; |
638
|
0
|
|
|
|
|
0
|
$inflate_ok++; |
639
|
|
|
|
|
|
|
}; |
640
|
|
|
|
|
|
|
|
641
|
0
|
|
|
|
|
0
|
return $inflate_ok; |
642
|
|
|
|
|
|
|
} |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
} # BEGIN |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
1; |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
=pod |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
=encoding UTF-8 |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
=head1 NAME |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
Net::HTTP::Methods - Methods shared by Net::HTTP and Net::HTTPS |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
=head1 VERSION |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
version 6.22 |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
=head1 AUTHOR |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
Gisle Aas |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
This software is copyright (c) 2001 by Gisle Aas. |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
669
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
=cut |
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
__END__ |