summaryrefslogtreecommitdiff
path: root/cpan/HTTP-Tiny
diff options
context:
space:
mode:
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>2013-06-21 22:14:39 +0100
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>2013-06-21 22:14:39 +0100
commit9a00675db41cb2119a7340d679a1d86f89dd83bf (patch)
treeb3997ee73fda72d8d5d3fe1ae3982cc75e58a336 /cpan/HTTP-Tiny
parent5a50c7c8970381e0720b875dd03ba17bb794712b (diff)
downloadperl-9a00675db41cb2119a7340d679a1d86f89dd83bf.tar.gz
Update HTTP-Tiny to CPAN version 0.033
[DELTA] 0.033 2013-06-21 06:26:51 America/New_York [FIXED] - Modifying the 'agent' attribute with the accessor will append the default agent string, just like setting it during construction 0.032 2013-06-20 11:41:24 America/New_York [ADDED] - Added 'no_proxy' attribute, defaulting to $ENV{no_proxy}
Diffstat (limited to 'cpan/HTTP-Tiny')
-rw-r--r--cpan/HTTP-Tiny/lib/HTTP/Tiny.pm79
-rw-r--r--cpan/HTTP-Tiny/t/001_api.t2
-rw-r--r--cpan/HTTP-Tiny/t/003_agent.t22
-rw-r--r--cpan/HTTP-Tiny/t/141_no_proxy.t72
4 files changed, 158 insertions, 17 deletions
diff --git a/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm b/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm
index 45a1e371ec..2b9b7033dc 100644
--- a/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm
+++ b/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm
@@ -3,14 +3,14 @@ package HTTP::Tiny;
use strict;
use warnings;
# ABSTRACT: A small, simple, correct HTTP/1.1 client
-our $VERSION = '0.031'; # VERSION
+our $VERSION = '0.033'; # VERSION
use Carp ();
my @attributes;
BEGIN {
- @attributes = qw(agent cookie_jar default_headers local_address max_redirect max_size proxy timeout SSL_options verify_SSL);
+ @attributes = qw(cookie_jar default_headers local_address max_redirect max_size proxy no_proxy timeout SSL_options verify_SSL);
no strict 'refs';
for my $accessor ( @attributes ) {
*{$accessor} = sub {
@@ -19,21 +19,26 @@ BEGIN {
}
}
+sub agent {
+ my($self, $agent) = @_;
+ if( @_ > 1 ){
+ $self->{agent} =
+ (defined $agent && $agent =~ / $/) ? $agent . $self->_agent : $agent;
+ }
+ return $self->{agent};
+}
+
sub new {
my($class, %args) = @_;
- (my $default_agent = $class) =~ s{::}{-}g;
- $default_agent .= "/" . ($class->VERSION || 0);
-
my $self = {
- agent => $default_agent,
max_redirect => 5,
timeout => 60,
verify_SSL => $args{verify_SSL} || $args{verify_ssl} || 0, # no verification by default
+ no_proxy => $ENV{no_proxy},
};
- $args{agent} .= $default_agent
- if defined $args{agent} && $args{agent} =~ / $/;
+ bless $self, $class;
$class->_validate_cookie_jar( $args{cookie_jar} ) if $args{cookie_jar};
@@ -41,6 +46,8 @@ sub new {
$self->{$key} = $args{$key} if exists $args{$key}
}
+ $self->agent( exists $args{agent} ? $args{agent} : $class->_agent );
+
# Never override proxy argument as this breaks backwards compat.
if (!exists $self->{proxy} && (my $http_proxy = $ENV{http_proxy})) {
if ($http_proxy =~ m{\Ahttp://[^/?#:@]+:\d+/?\z}) {
@@ -51,7 +58,13 @@ sub new {
}
}
- return bless $self, $class;
+ # Split no_proxy to array reference if not provided as such
+ unless ( ref $self->{no_proxy} eq 'ARRAY' ) {
+ $self->{no_proxy} =
+ (defined $self->{no_proxy}) ? [ split /\s*,\s*/, $self->{no_proxy} ] : [];
+ }
+
+ return $self;
}
@@ -188,6 +201,12 @@ my %DefaultPort = (
https => 443,
);
+sub _agent {
+ my $class = ref($_[0]) || $_[0];
+ (my $default_agent = $class) =~ s{::}{-}g;
+ return $default_agent . "/" . ($class->VERSION || 0);
+}
+
sub _request {
my ($self, $method, $url, $args) = @_;
@@ -208,7 +227,7 @@ sub _request {
local_address => $self->{local_address},
);
- if ($self->{proxy}) {
+ if ($self->{proxy} && ! grep { $host =~ /\Q$_\E$/ } @{$self->{no_proxy}}) {
$request->{uri} = "$scheme://$request->{host_port}$path_query";
die(qq/HTTPS via proxy is not supported\n/)
if $request->{scheme} eq 'https';
@@ -974,7 +993,7 @@ HTTP::Tiny - A small, simple, correct HTTP/1.1 client
=head1 VERSION
-version 0.031
+version 0.033
=head1 SYNOPSIS
@@ -1058,6 +1077,12 @@ URL of a proxy server to use (default is C<$ENV{http_proxy}> if set)
=item *
+C<no_proxy>
+
+List of domain suffixes that should not be proxied. Must be a comma-separated string or an array reference. (default is C<$ENV{no_proxy}>)
+
+=item *
+
C<timeout>
Request timeout in seconds (default is 60)
@@ -1262,6 +1287,7 @@ local_address
max_redirect
max_size
proxy
+no_proxy
timeout
verify_SSL
SSL_options
@@ -1397,6 +1423,13 @@ undef), then the C<http_proxy> environment variable is ignored.
=item *
+C<no_proxy> environment variable is supported in the format comma-separated
+list of domain extensions proxy should not be used for. If a C<no_proxy>
+argument is passed to C<new>, then the C<no_proxy> environment variable is
+ignored.
+
+=item *
+
There is no provision for delaying a request body using an C<Expect> header.
Unexpected C<1XX> responses are silently ignored as per the specification.
@@ -1420,19 +1453,27 @@ There is no support for IPv6 of any kind.
=item *
-L<LWP::UserAgent>
+L<HTTP::Thin> - HTTP::Tiny wrapper with L<HTTP::Request>/L<HTTP::Response> compatibility
+
+=item *
+
+L<HTTP::Tiny::Mech> - Wrap L<WWW::Mechanize> instance in HTTP::Tiny compatible interface
=item *
-L<IO::Socket::SSL>
+L<IO::Socket::SSL> - Required for SSL support
=item *
-L<Mozilla::CA>
+L<LWP::UserAgent> - If HTTP::Tiny isn't enough for you, this is the "standard" way to do things
=item *
-L<Net::SSLeay>
+L<Mozilla::CA> - Required if you want to validate SSL certificates
+
+=item *
+
+L<Net::SSLeay> - Required for SSL support
=back
@@ -1483,6 +1524,10 @@ Alessandro Ghedini <al3xbio@gmail.com>
=item *
+Brad Gilbert <bgills@cpan.org>
+
+=item *
+
Chris Nehren <apeiron@cpan.org>
=item *
@@ -1527,6 +1572,10 @@ Serguei Trouchelle <stro@cpan.org>
=item *
+Syohei YOSHIDA <syohex@gmail.com>
+
+=item *
+
Tony Cook <tony@develop-help.com>
=back
diff --git a/cpan/HTTP-Tiny/t/001_api.t b/cpan/HTTP-Tiny/t/001_api.t
index 0083c2e2b4..0111851e03 100644
--- a/cpan/HTTP-Tiny/t/001_api.t
+++ b/cpan/HTTP-Tiny/t/001_api.t
@@ -7,7 +7,7 @@ use Test::More tests => 2;
use HTTP::Tiny;
my @accessors = qw(
- agent default_headers local_address max_redirect max_size proxy timeout SSL_options verify_SSL cookie_jar
+ agent default_headers local_address max_redirect max_size proxy no_proxy timeout SSL_options verify_SSL cookie_jar
);
my @methods = qw(
new get head put post delete post_form request mirror www_form_urlencode
diff --git a/cpan/HTTP-Tiny/t/003_agent.t b/cpan/HTTP-Tiny/t/003_agent.t
index 274917d2da..6962c66832 100644
--- a/cpan/HTTP-Tiny/t/003_agent.t
+++ b/cpan/HTTP-Tiny/t/003_agent.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 8;
use HTTP::Tiny;
# a couple tests to ensure that we get the default agent expected, the coorect
@@ -31,3 +31,23 @@ my $default = 'HTTP-Tiny/' . (HTTP::Tiny->VERSION || 0);
'agent string is as properly appended to',
;
}
+
+{
+ my $ua = HTTP::Tiny->new();
+
+ is( HTTP::Tiny->_agent(), $default, 'check _agent on class' );
+ is $ua->_agent(), $default, 'check _agent on object';
+
+ $ua->agent(undef);
+ is $ua->agent, undef, 'agent string is empty';
+
+ $ua->agent('something else');
+ is $ua->agent, 'something else', 'agent string is as expected';
+
+ $ua->agent('something else ');
+ is
+ $ua->agent,
+ "something else $default",
+ 'agent string is as properly appended to',
+ ;
+}
diff --git a/cpan/HTTP-Tiny/t/141_no_proxy.t b/cpan/HTTP-Tiny/t/141_no_proxy.t
new file mode 100644
index 0000000000..f12a268d1d
--- /dev/null
+++ b/cpan/HTTP-Tiny/t/141_no_proxy.t
@@ -0,0 +1,72 @@
+#!perl
+use strict;
+use warnings;
+
+use Test::More 0.88;
+
+use HTTP::Tiny;
+
+# blank slate for testing
+delete $ENV{no_proxy};
+
+{
+ my $c = HTTP::Tiny->new();
+ is_deeply( $c->no_proxy, [], "no no_proxy given" );
+}
+
+my @cases = (
+ #<<< No perltidy
+ {
+ no_proxy => [
+ undef,
+ [],
+ ],
+ expect => [],
+ },
+ {
+ no_proxy => [
+ "localhost",
+ ["localhost"],
+ ],
+ expect => ["localhost"],
+ },
+ {
+ no_proxy => [
+ "localhost,example.com",
+ "localhost, example.com",
+ [qw/localhost example.com/]
+ ],
+ expect => [ "localhost", "example.com" ],
+ },
+ #>>>
+);
+
+for my $c (@cases) {
+ for my $no_proxy ( @{ $c->{no_proxy} } ) {
+ my $label =
+ !defined $no_proxy ? 'undef'
+ : ref $no_proxy ? "[qw/@$no_proxy/]"
+ : "'$no_proxy'";
+
+ # Can't test environment with array ref (ENV stringifies in new perls)
+ if ( ref $no_proxy ) {
+ my $ht = HTTP::Tiny->new( no_proxy => $no_proxy );
+ is_deeply( $ht->no_proxy, $c->{expect}, "new(no_proxy => $label)" );
+ }
+ else {
+ {
+ local $ENV{no_proxy} = $no_proxy;
+ my $ht = HTTP::Tiny->new();
+ is_deeply( $ht->no_proxy, $c->{expect}, "\$ENV{no_proxy} = $label" );
+ }
+ {
+ local $ENV{no_proxy} = "Shouldnt,see,this";
+ my $ht = HTTP::Tiny->new( no_proxy => $no_proxy );
+ is_deeply( $ht->no_proxy, $c->{expect},
+ "new(no_proxy => $label) versus other \$ENV{no_proxy}" );
+ }
+ }
+ }
+}
+
+done_testing();