blib/lib/LWP/Protocol/GHTTP.pm

filter: Statementstmt 88.2% 15 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.3% 21 / 23 CC 1 SCAR 0.5
CC
1
Cov
88%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package LWP::Protocol::GHTTP;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use base 'LWP::Protocol';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 0 ▶use HTTP::GHTTP qw(METHOD_GET METHOD_HEAD METHOD_POST);
Subroutine BEGIN: called CC=1 SCAR=2.6
11 use HTTP::Response ();
12 use HTTP::Status qw(:constants);
13 use IO::Handle ();
14 use Try::Tiny qw(try catch);
15 use utf8;
16  
17 our $VERSION = '6.16';
18  
19 my %METHOD = (GET => METHOD_GET, HEAD => METHOD_HEAD, POST => METHOD_POST,);
20  
21 sub request {
22 my ($self, $request, $proxy, $arg, $size, $timeout) = @_;
23  
24 my $method = $request->method;
25 unless (exists $METHOD{$method}) {
26 return HTTP::Response->new(HTTP_BAD_REQUEST, "Bad method '$method'");
27 }
28  
29 my $r = HTTP::GHTTP->new($request->uri);
30  
31 # XXX what headers for repeated headers here?
32 $request->headers->scan(sub { $r->set_header(@_) });
33  
34 $r->set_type($METHOD{$method});
35  
36 # XXX should also deal with subroutine content.
37 my $cref = $request->content_ref;
38 $r->set_body($$cref) if length($$cref);
39  
40 # XXX is this right
41 $r->set_proxy($proxy->as_string) if $proxy;
42  
43 $r->process_request;
44  
45 my $response = HTTP::Response->new($r->get_status);
46  
47 # XXX How can get the headers out of $r?? This way is too stupid.
48 my @headers = try {
49 return $r->get_headers(); # not always available
50 }
51 catch {
52 return
53 qw(Date Connection Server Content-type Accept-Ranges Server Content-Length Last-Modified ETag);
54 };
55 for my $head (@headers) {
56 my $v = $r->get_header($head);
57 $response->header($head => $v) if defined $v;
58 }
59  
60 return $self->collect_once($arg, $response, $r->get_body);
61 }
62  
63 1; # End of LWP::Protocol::GHTTP
64  
65 =encoding utf8
66  
67 =head1 NAME
68  
69 LWP::Protocol::GHTTP - (DEPRECATED) Provide GHTTP support for L<LWP::UserAgent> via L<HTTP::GHTTP>.
70  
71 =head1 SYNOPSIS
72  
73 use strict;
74 use warnings;
75 use LWP::UserAgent;
76  
77 # create a new object
78 LWP::Protocol::implementor('http', 'LWP::Protocol::GHTTP');
79 my $ua = LWP::UserAgent->new();
80 my $res = $ua->get('http://www.example.com');
81 # note that we can only support the GET HEAD and POST verbs.
82  
83 =head1 DESCRIPTION
84  
85 This module depends on the GNOME libghttp
86 L<http://ftp.gnome.org/pub/gnome/sources/libghttp> project. That project is no
87 longer in development. If you are trying to use this module, you'd likely do
88 better to just use L<LWP::Protocol::http> or L<LWP::Protocol::https>.
89  
90 L<LWP::Protocol::GHTTP> is only capable of dispatching requests using the C<GET>,
91 C<POST>, or C<HEAD> verbs.
92  
93 You have been warned.
94  
95 The L<LWP::Protocol::GHTTP> module provides support for using HTTP schemed URLs
96 with LWP. This module is a plug-in to the LWP protocol handling, but since it
97 takes over the HTTP scheme, you have to tell LWP we want to use this plug-in by
98 calling L<LWP::Protocol>'s C<implementor> function.
99  
100 This module used to be bundled with L<libwww-perl>, but it was unbundled in
101 v6.16 in order to be able to declare its dependencies properly for the CPAN
102 tool-chain. Applications that need GHTTP support can just declare their
103 dependency on L<LWP::Protocol::GHTTP> and will no longer need to know what
104 underlying modules to install.
105  
106 =head1 CAVEATS
107  
108 WARNING!
109  
110 This module depends on the GNOME libghttp
111 L<http://ftp.gnome.org/pub/gnome/sources/libghttp> project. That project is no
112 longer in development. If you are trying to use this module, you'd likely do
113 better to just use L<LWP::Protocol::http> or L<LWP::Protocol::https>.
114  
115 Also, L<LWP::Protocol::GHTTP> is only capable of dispatching requests using the C<GET>,
116 C<POST>, or C<HEAD> verbs.
117  
118 =head1 FUNCTIONS
119  
120 L<LWP::Protocol::GHTTP> inherits all functions from L<LWP::Protocol> and provides the following
121 overriding functions.
122  
123 =head2 request
124  
125 my $response = $ua->request($request, $proxy, undef);
126 my $response = $ua->request($request, $proxy, '/tmp/sss');
127 my $response = $ua->request($request, $proxy, \&callback, 1024);
128  
129 Dispatches a request over the HTTP protocol and returns a response object.
130 Refer to L<LWP::UserAgent> for description of the arguments.
131  
132 =head1 AUTHOR
133  
134 Gisle Aas <F<gisle@ActiveState.com>>
135  
136 =head1 CONTRIBUTORS
137  
138 =over 4
139  
140 =item *
141  
142 Chase Whitener <F<capoeirab@cpan.org>>
143  
144 =back
145  
146 =head1 BUGS
147  
148 Please report any bugs or feature requests on GitHub L<https://github.com/genio/lwp-protocol-ghttp/issues>.
149 We appreciate any and all criticism, bug reports, enhancements, or fixes.
150  
151 =head1 LICENSE AND COPYRIGHT
152  
153 Copyright 1997-2011 Gisle Aas.
154  
155 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
156  
157 =cut
↑ Summary