@ISA
=
qw(LWP::Protocol)
;
sub
request
{
my
(
$self
,
$request
,
$proxy
,
$arg
,
$size
) =
@_
;
if
(
defined
$proxy
)
{
return
new HTTP::Response
&HTTP::Status::RC_BAD_REQUEST
,
'You can not proxy with data'
;
}
my
$method
=
$request
->method;
unless
(
$method
eq
'GET'
||
$method
eq
'HEAD'
) {
return
new HTTP::Response
&HTTP::Status::RC_BAD_REQUEST
,
'Library does not allow method '
.
"$method for 'data:' URLs"
;
}
my
$url
=
$request
->url;
my
$response
= new HTTP::Response
&HTTP::Status::RC_OK
,
"Document follows"
;
my
$media_type
=
$url
->media_type;
my
$data
=
$url
->data;
$response
->header(
'Content-Type'
=>
$media_type
,
'Content-Length'
=>
length
(
$data
),
'Date'
=> time2str(
time
),
'Server'
=>
"libwww-perl-internal/$LWP::VERSION"
);
$response
->content(
$data
)
if
$method
ne
"HEAD"
;
return
$response
;
}
1;