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.

68 lines
1.6 KiB

  1. package LWP::Protocol::GHTTP;
  2. # $Id: GHTTP.pm,v 1.1 2000/11/30 05:59:15 gisle Exp $
  3. #
  4. # You can tell LWP to use this module for 'http' requests by running
  5. # code like this before you make requests:
  6. #
  7. # require LWP::Protocol::GHTTP;
  8. # LWP::Protocol::implementor('http', 'LWP::Protocol::GHTTP');
  9. #
  10. use strict;
  11. use vars qw(@ISA);
  12. require LWP::Protocol;
  13. @ISA=qw(LWP::Protocol);
  14. require HTTP::Response;
  15. require HTTP::Status;
  16. use HTTP::GHTTP qw(METHOD_GET METHOD_HEAD METHOD_POST);
  17. my %METHOD =
  18. (
  19. GET => METHOD_GET,
  20. HEAD => METHOD_HEAD,
  21. POST => METHOD_POST,
  22. );
  23. sub request
  24. {
  25. my($self, $request, $proxy, $arg, $size, $timeout) = @_;
  26. my $method = $request->method;
  27. unless (exists $METHOD{$method}) {
  28. return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
  29. "Bad method '$method'");
  30. }
  31. my $r = HTTP::GHTTP->new($request->uri);
  32. # XXX what headers for repeated headers here?
  33. $request->headers->scan(sub { $r->set_header(@_)});
  34. $r->set_type($METHOD{$method});
  35. # XXX should also deal with subroutine content.
  36. my $cref = $request->content_ref;
  37. $r->set_body($$cref) if length($$cref);
  38. # XXX is this right
  39. $r->set_proxy($proxy->as_string) if $proxy;
  40. $r->process_request;
  41. my $response = HTTP::Response->new($r->get_status);
  42. # XXX How can get the headers out of $r?? This way is too stupid.
  43. for (qw(Date Server Content-type Last-Modified ETag)) {
  44. my $v = $r->get_header($_);
  45. $response->header($_ => $v) if $v;
  46. }
  47. return $self->collect_once($arg, $response, $r->get_body);
  48. }
  49. 1;