1 package LWP::Protocol::GHTTP;
3 # You can tell LWP to use this module for 'http' requests by running
4 # code like this before you make requests:
6 # require LWP::Protocol::GHTTP;
7 # LWP::Protocol::implementor('http', 'LWP::Protocol::GHTTP');
13 require LWP::Protocol;
14 @ISA=qw(LWP::Protocol);
16 require HTTP::Response;
19 use HTTP::GHTTP qw(METHOD_GET METHOD_HEAD METHOD_POST);
30 my($self, $request, $proxy, $arg, $size, $timeout) = @_;
32 my $method = $request->method;
33 unless (exists $METHOD{$method}) {
34 return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
35 "Bad method '$method'");
38 my $r = HTTP::GHTTP->new($request->uri);
40 # XXX what headers for repeated headers here?
41 $request->headers->scan(sub { $r->set_header(@_)});
43 $r->set_type($METHOD{$method});
45 # XXX should also deal with subroutine content.
46 my $cref = $request->content_ref;
47 $r->set_body($$cref) if length($$cref);
50 $r->set_proxy($proxy->as_string) if $proxy;
54 my $response = HTTP::Response->new($r->get_status);
56 # XXX How can get the headers out of $r?? This way is too stupid.
59 # Wrapped in eval because this method is not always available
60 @headers = $r->get_headers;
62 @headers = qw(Date Connection Server Content-type
64 Content-Length Last-Modified ETag) if $@;
66 my $v = $r->get_header($_);
67 $response->header($_ => $v) if defined $v;
70 return $self->collect_once($arg, $response, $r->get_body);