Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB

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