Skip to content

Commit

Permalink
initial HTTP::UserAgent implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sergot committed Jun 24, 2014
1 parent 252afde commit ec2c28f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/HTTP/UserAgent.pm6
Expand Up @@ -46,6 +46,10 @@ multi _split_buf(Blob $delimiter, Buf $input, $limit = Inf --> List) {
@result
}

submethod BUILD(:$!useragent?) {
$!useragent = get-ua($!useragent) if $!useragent.defined;
}

method get(Str $url is copy) {
$url = _clear-url($url);

Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions t/08-ua.t
@@ -0,0 +1,23 @@
use v6;
use HTTP::UserAgent;
use HTTP::UserAgent::Common;
use Test;

plan 6;

# new
my $ua = HTTP::UserAgent.new;
is $ua.useragent, '', 'new 1/3';

$ua = HTTP::UserAgent.new(:useragent('test'));
is $ua.useragent, 'test', 'new 2/3';

my $newua = get-ua('chrome_linux');
$ua = HTTP::UserAgent.new(:useragent('chrome_linux'));
is $ua.useragent, $newua, 'new 3/3';

# get
my $response = $ua.get('filip.sergot.pl');
ok $response, 'get 1/?';
isa_ok $response, HTTP::Response, 'get 2/?';
ok $response.is-success, 'get 3/?';

0 comments on commit ec2c28f

Please sign in to comment.