Skip to content

Commit

Permalink
no need for default public suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 9, 2015
1 parent 8aab5b3 commit 060bb72
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -513,6 +513,9 @@ L<Mojo::UserAgent::CookieJar> object.
# Disable collecting cookies from responses
$ua->cookie_jar->collecting(0);
# Ignore cookies for certain public suffixes
$ua->cookie_jar->public_suffixes(['com', 'net', 'org']);
# Add custom cookie to the jar
$ua->cookie_jar->add(
Mojo::Cookie::Response->new(
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -6,7 +6,7 @@ use Mojo::Path;

has collecting => 1;
has max_cookie_size => 4096;
has public_suffixes => sub { ['com'] };
has public_suffixes => sub { [] };

sub add {
my ($self, @cookies) = @_;
Expand Down Expand Up @@ -170,9 +170,9 @@ Maximum cookie size in bytes, defaults to C<4096> (4KB).
my $suffixes = $jar->public_suffixes;
$jar = $jar->public_suffixes(['com', 'net', 'org']);
Public suffixes for which cookies should always be ignored, defaults to C<com>.
A comprehensive list of public suffixes currently being used across the internet
can be found at L<https://publicsuffix.org>.
Public suffixes for which cookies should always be ignored. A comprehensive list
of public suffixes currently being used across the internet can be found at
L<https://publicsuffix.org>.
=head1 METHODS
Expand Down
29 changes: 28 additions & 1 deletion t/mojo/cookiejar.t
Expand Up @@ -347,7 +347,7 @@ is $tx->req->cookie('foo')->name, 'foo', 'right name';
is $tx->req->cookie('foo')->value, 'local', 'right value';
is $tx->req->cookie('bar'), undef, 'no cookie';

# Gather and prepare cookies for public suffix (with IDNA)
# Gather and prepare cookies for unknown public suffix (with IDNA)
$jar = Mojo::UserAgent::CookieJar->new;
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://bücher.com/foo');
Expand All @@ -369,6 +369,33 @@ $jar->collect($tx);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://bücher.com/foo');
$jar->prepare($tx);
is $tx->req->cookie('foo')->name, 'foo', 'right name';
is $tx->req->cookie('foo')->value, 'bar', 'right value';
is $tx->req->cookie('bar')->name, 'bar', 'right name';
is $tx->req->cookie('bar')->value, 'baz', 'right value';

# Gather and prepare cookies for public suffix (with IDNA)
$jar = Mojo::UserAgent::CookieJar->new;
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://bücher.com/foo');
$tx->res->cookies(
Mojo::Cookie::Response->new(
domain => 'com',
path => '/foo',
name => 'foo',
value => 'bar'
),
Mojo::Cookie::Response->new(
domain => 'xn--bcher-kva.com',
path => '/foo',
name => 'bar',
value => 'baz'
)
);
$jar->public_suffixes(['com'])->collect($tx);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://bücher.com/foo');
$jar->prepare($tx);
is $tx->req->cookie('foo'), undef, 'no cookie';
is $tx->req->cookie('bar')->name, 'bar', 'right name';
is $tx->req->cookie('bar')->value, 'baz', 'right value';
Expand Down

0 comments on commit 060bb72

Please sign in to comment.