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