line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LWP::Protocol::data; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Implements access to data:-URLs as specified in RFC 2397 |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '6.34'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require HTTP::Response; |
10
|
|
|
|
|
|
|
require HTTP::Status; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use base qw(LWP::Protocol); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
106
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
7
|
use HTTP::Date qw(time2str); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
237
|
|
15
|
|
|
|
|
|
|
require LWP; # needs version number |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub request |
18
|
|
|
|
|
|
|
{ |
19
|
1
|
|
|
1
|
1
|
3
|
my($self, $request, $proxy, $arg, $size) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# check proxy |
22
|
1
|
50
|
|
|
|
2
|
if (defined $proxy) |
23
|
|
|
|
|
|
|
{ |
24
|
0
|
|
|
|
|
0
|
return HTTP::Response->new( HTTP::Status::RC_BAD_REQUEST, |
25
|
|
|
|
|
|
|
'You can not proxy with data'); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# check method |
29
|
1
|
|
|
|
|
3
|
my $method = $request->method; |
30
|
1
|
50
|
33
|
|
|
15
|
unless ($method eq 'GET' || $method eq 'HEAD') { |
31
|
0
|
|
|
|
|
0
|
return HTTP::Response->new( HTTP::Status::RC_BAD_REQUEST, |
32
|
|
|
|
|
|
|
'Library does not allow method ' . |
33
|
|
|
|
|
|
|
"$method for 'data:' URLs"); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
2
|
my $url = $request->uri; |
37
|
1
|
|
|
|
|
8
|
my $response = HTTP::Response->new( HTTP::Status::RC_OK, "Document follows"); |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
37
|
my $media_type = $url->media_type; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
68
|
my $data = $url->data; |
42
|
1
|
|
|
|
|
90
|
$response->header('Content-Type' => $media_type, |
43
|
|
|
|
|
|
|
'Content-Length' => length($data), |
44
|
|
|
|
|
|
|
'Date' => time2str(time), |
45
|
|
|
|
|
|
|
'Server' => "libwww-perl-internal/$LWP::VERSION" |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
1
|
50
|
|
|
|
131
|
$data = "" if $method eq "HEAD"; |
49
|
1
|
|
|
|
|
5
|
return $self->collect_once($arg, $response, $data); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |