Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 9, 2013
1 parent 5fa8130 commit 97f463f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

4.35 2013-09-09
4.35 2013-09-10
- Added origin attribute to Mojo::Cookie::Response.
- Fixed RFC 6265 compliance bugs in Mojo::Cookie::Request,
Mojo::Cookie::Response and Mojo::UserAgent::CookieJar.
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -19,12 +19,12 @@ sub add {
next if length($cookie->value // '') > $size;

# Replace cookie
my $origin = $cookie->origin;
next unless my $domain = $cookie->domain // $origin;
my $origin = $cookie->origin // '';
next unless my $domain = lc($cookie->domain // $origin);
$domain =~ s/^\.//;
next unless my $path = $cookie->path;
next unless length(my $name = $cookie->name // '');
my $jar = $self->{jar}{lc $domain} ||= [];
my $jar = $self->{jar}{$domain} ||= [];
@$jar = (grep({_compare($_, $path, $name, $origin)} @$jar), $cookie);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ sub find {
# Grab cookies
my $new = $self->{jar}{$domain} = [];
for my $cookie (@$old) {
if (my $origin = $cookie->origin) { next unless $host eq $origin }
next unless $cookie->domain || $host eq $cookie->origin;

# Check if cookie has expired
my $expires = $cookie->expires;
Expand Down Expand Up @@ -102,7 +102,7 @@ sub inject {
sub _compare {
my ($cookie, $path, $name, $origin) = @_;
return 1 if $cookie->path ne $path || $cookie->name ne $name;
return ($cookie->origin // '') ne ($origin // '');
return ($cookie->origin // '') ne $origin;
}

sub _path { $_[0] eq '/' || $_[0] eq $_[1] || $_[1] =~ m!^\Q$_[0]/! }
Expand Down

0 comments on commit 97f463f

Please sign in to comment.