]> Dogcows Code - chaz/p5-HTTP-AnyUA/blob - lib/HTTP/AnyUA/Backend/Furl.pm
Version 0.900
[chaz/p5-HTTP-AnyUA] / lib / HTTP / AnyUA / Backend / Furl.pm
1 package HTTP::AnyUA::Backend::Furl;
2 # ABSTRACT: A unified programming interface for Furl
3
4
5 use warnings;
6 use strict;
7
8 our $VERSION = '0.900'; # VERSION
9
10 use parent 'HTTP::AnyUA::Backend';
11
12 use HTTP::AnyUA::Util;
13
14
15 sub request {
16 my $self = shift;
17 my ($method, $url, $args) = @_;
18
19 local $args->{content} = HTTP::AnyUA::Util::coderef_content_to_string($args->{content});
20
21 my $request = HTTP::AnyUA::Util::native_to_http_request(@_);
22 my $ua_resp = $self->ua->request($request);
23
24 return $self->_munge_response($ua_resp, $args->{data_callback});
25 }
26
27 sub _munge_response {
28 my $self = shift;
29 my $ua_resp = shift;
30 my $data_cb = shift;
31
32 my $resp = {
33 success => !!$ua_resp->is_success,
34 url => $ua_resp->request->uri->as_string,
35 status => $ua_resp->code,
36 reason => $ua_resp->message,
37 headers => HTTP::AnyUA::Util::http_headers_to_native($ua_resp->headers),
38 };
39
40 $resp->{protocol} = $ua_resp->protocol if $ua_resp->protocol;
41
42 if ($resp->{headers}{'x-internal-response'}) {
43 HTTP::AnyUA::Util::internal_exception($ua_resp->content, $resp);
44 }
45 elsif ($data_cb) {
46 $data_cb->($ua_resp->content, $resp);
47 }
48 else {
49 $resp->{content} = $ua_resp->content;
50 }
51
52 return $resp;
53 }
54
55 1;
56
57 __END__
58
59 =pod
60
61 =encoding UTF-8
62
63 =head1 NAME
64
65 HTTP::AnyUA::Backend::Furl - A unified programming interface for Furl
66
67 =head1 VERSION
68
69 version 0.900
70
71 =head1 DESCRIPTION
72
73 This module adds support for the HTTP client L<Furl> to be used with the unified programming
74 interface provided by L<HTTP::AnyUA>.
75
76 =head1 CAVEATS
77
78 =over 4
79
80 =item *
81
82 L<Furl> doesn't keep a list of requests and responses along a redirect chain. As such, the C<url>
83
84 field in the response is always the same as the URL of the original request, and the C<redirects>
85 field is never used.
86
87 =back
88
89 =head1 SEE ALSO
90
91 =over 4
92
93 =item *
94
95 L<HTTP::AnyUA::Backend>
96
97 =back
98
99 =head1 BUGS
100
101 Please report any bugs or feature requests on the bugtracker website
102 L<https://github.com/chazmcgarvey/HTTP-AnyUA/issues>
103
104 When submitting a bug or request, please include a test-file or a
105 patch to an existing test-file that illustrates the bug or desired
106 feature.
107
108 =head1 AUTHOR
109
110 Charles McGarvey <chazmcgarvey@brokenzipper.com>
111
112 =head1 COPYRIGHT AND LICENSE
113
114 This software is copyright (c) 2017 by Charles McGarvey.
115
116 This is free software; you can redistribute it and/or modify it under
117 the same terms as the Perl 5 programming language system itself.
118
119 =cut
This page took 0.041893 seconds and 4 git commands to generate.