home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl_ste.zip / LWP / Protocol / data.pm next >
Text File  |  1996-12-10  |  1KB  |  54 lines

  1. #
  2. # $Id: data.pm,v 1.1 1996/12/10 14:41:25 aas Exp $
  3. #
  4. # Implements access to data:-URLs as specified in
  5. # draft-masinter-url-data-02.txt
  6.  
  7. package LWP::Protocol::data;
  8.  
  9. require HTTP::Response;
  10. require HTTP::Status;
  11.  
  12. require LWP::Protocol;
  13. @ISA = qw(LWP::Protocol);
  14.  
  15. use HTTP::Date qw(time2str);
  16. require LWP;  # needs version number
  17.  
  18. sub request
  19. {
  20.     my($self, $request, $proxy, $arg, $size) = @_;
  21.  
  22.     # check proxy
  23.     if (defined $proxy)
  24.     {
  25.     return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
  26.                   'You can not proxy with data';
  27.     }
  28.  
  29.     # check method
  30.     if ($request->method ne 'GET') {
  31.     return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
  32.                   'Library does not allow method ' .
  33.                   "$method for 'data:' URLs";
  34.     }
  35.  
  36.     my $url = $request->url;
  37.     my $response = new HTTP::Response &HTTP::Status::RC_OK, "Document follows";
  38.  
  39.     my($media_type, $params) = $url->media_type;
  40.     $media_type .= ";$params" if $params;
  41.  
  42.     my $data = $url->data;
  43.     $response->header('Content-Type'   => $media_type,
  44.               'Content-Length' => length($data),
  45.               'Date'           => time2str(time),
  46.               'Server'         => "libwww-perl-internal/$LWP::VERSION"
  47.              );
  48.     $response->content($data);
  49.  
  50.     return $response;
  51. }
  52.  
  53. 1;
  54.