<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package LWP::Protocol::data;

# Implements access to data:-URLs as specified in RFC 2397

use strict;

our $VERSION = '6.77';

require HTTP::Response;
require HTTP::Status;

use parent qw(LWP::Protocol);

use HTTP::Date qw(time2str);
require LWP;  # needs version number

sub request
{
    my($self, $request, $proxy, $arg, $size) = @_;

    # check proxy
    if (defined $proxy)
    {
	return HTTP::Response-&gt;new( HTTP::Status::RC_BAD_REQUEST,
				  'You can not proxy with data');
    }

    # check method
    my $method = $request-&gt;method;
    unless ($method eq 'GET' || $method eq 'HEAD') {
	return HTTP::Response-&gt;new( HTTP::Status::RC_BAD_REQUEST,
				  'Library does not allow method ' .
				  "$method for 'data:' URLs");
    }

    my $url = $request-&gt;uri;
    my $response = HTTP::Response-&gt;new( HTTP::Status::RC_OK, "Document follows");

    my $media_type = $url-&gt;media_type;

    my $data = $url-&gt;data;
    $response-&gt;header('Content-Type'   =&gt; $media_type,
		      'Content-Length' =&gt; length($data),
		      'Date'           =&gt; time2str(time),
		      'Server'         =&gt; "libwww-perl-internal/$LWP::VERSION"
		     );

    $data = "" if $method eq "HEAD";
    return $self-&gt;collect_once($arg, $response, $data);
}

1;
</pre></body></html>