| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package LWP::Protocol::GHTTP; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
67226
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
19
|
|
|
5
|
1
|
|
|
1
|
|
14
|
use 5.008001; |
|
|
1
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use base 'LWP::Protocol'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
413
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1348
|
use Carp (); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
15
|
|
|
10
|
1
|
|
|
1
|
|
971
|
use HTTP::GHTTP qw(METHOD_GET METHOD_HEAD METHOD_POST); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
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 via L. |
|
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 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 or L. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L is only capable of dispatching requests using the C, |
|
91
|
|
|
|
|
|
|
C, or C verbs. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
You have been warned. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The L 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's C function. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This module used to be bundled with L, 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 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 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 or L. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Also, L is only capable of dispatching requests using the C, |
|
116
|
|
|
|
|
|
|
C, or C verbs. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L inherits all functions from L 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 for description of the arguments. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Gisle Aas > |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over 4 |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Chase Whitener > |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 BUGS |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Please report any bugs or feature requests on GitHub L. |
|
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 |