cpan/HTTP-Tiny/t/000_load.t
cpan/HTTP-Tiny/t/001_api.t
cpan/HTTP-Tiny/t/002_croakage.t
+cpan/HTTP-Tiny/t/003_agent.t
cpan/HTTP-Tiny/t/00-compile.t
cpan/HTTP-Tiny/t/010_url.t
cpan/HTTP-Tiny/t/020_headers.t
'HTTP::Tiny' => {
'MAINTAINER' => 'dagolden',
- 'DISTRIBUTION' => 'DAGOLDEN/HTTP-Tiny-0.024.tar.gz',
+ 'DISTRIBUTION' => 'DAGOLDEN/HTTP-Tiny-0.025.tar.gz',
'FILES' => q[cpan/HTTP-Tiny],
'EXCLUDED' => [
't/00-report-prereqs.t',
use strict;
use warnings;
# ABSTRACT: A small, simple, correct HTTP/1.1 client
-our $VERSION = '0.024'; # VERSION
+our $VERSION = '0.025'; # VERSION
use Carp ();
sub new {
my($class, %args) = @_;
- (my $agent = $class) =~ s{::}{-}g;
+
+ (my $default_agent = $class) =~ s{::}{-}g;
+ $default_agent .= "/" . ($class->VERSION || 0);
+
my $self = {
- agent => $agent . "/" . ($class->VERSION || 0),
+ agent => $default_agent,
max_redirect => 5,
timeout => 60,
verify_SSL => $args{verify_SSL} || $args{verify_ssl} || 0, # no verification by default
};
+
+ $args{agent} .= $default_agent
+ if defined $args{agent} && $args{agent} =~ / $/;
+
for my $key ( @attributes ) {
$self->{$key} = $args{$key} if exists $args{$key}
}
=head1 VERSION
-version 0.024
+version 0.025
=head1 SYNOPSIS
C<agent>
-A user-agent string (defaults to 'HTTP::Tiny/$VERSION')
+A user-agent string (defaults to 'HTTP-Tiny/$VERSION'). If C<agent> ends in a space character, the default user-agent string is appended.
=item *
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+use HTTP::Tiny;
+
+# a couple tests to ensure that we get the default agent expected, the coorect
+# agent when specified, and the correct agent when specifified with a space at
+# the end of the string (as LWP::UserAgent does)
+
+
+my $default = 'HTTP-Tiny/' . (HTTP::Tiny->VERSION || 0);
+
+{
+ my $ua = HTTP::Tiny->new();
+ is $ua->agent, $default, 'default agent string is as expected';
+}
+
+{
+ my $ua = HTTP::Tiny->new(agent => 'something else');
+ is $ua->agent, 'something else', 'agent string is as expected';
+}
+
+{
+ my $ua = HTTP::Tiny->new(agent => 'something else ');
+ is
+ $ua->agent,
+ "something else $default",
+ 'agent string is as properly appended to',
+ ;
+}