1 package LWP::Protocol::data;
3 # Implements access to data:-URLs as specified in RFC 2397
8 require HTTP::Response;
11 require LWP::Protocol;
12 @ISA = qw(LWP::Protocol);
14 use HTTP::Date qw(time2str);
15 require LWP; # needs version number
19 my($self, $request, $proxy, $arg, $size) = @_;
24 return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
25 'You can not proxy with data';
29 my $method = $request->method;
30 unless ($method eq 'GET' || $method eq 'HEAD') {
31 return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
32 'Library does not allow method ' .
33 "$method for 'data:' URLs";
36 my $url = $request->url;
37 my $response = new HTTP::Response &HTTP::Status::RC_OK, "Document follows";
39 my $media_type = $url->media_type;
41 my $data = $url->data;
42 $response->header('Content-Type' => $media_type,
43 'Content-Length' => length($data),
44 'Date' => time2str(time),
45 'Server' => "libwww-perl-internal/$LWP::VERSION"
47 $response->content($data) if $method ne "HEAD";