Skip to content

Commit

Permalink
the world is not ready for a nomnomnom method yet
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 25, 2015
1 parent da15213 commit fdffd33
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 53 deletions.
8 changes: 4 additions & 4 deletions Changes
@@ -1,5 +1,5 @@

6.0 2015-02-25
6.0 2015-02-26
- Code name "Clinking Beer Mugs", this is a major release.
- Removed name listing support from param method in Mojolicious::Controller.
- Removed name listing support from param method in Mojo::Parameters.
Expand Down Expand Up @@ -29,13 +29,13 @@
- Renamed current attribute in Mojolicious::Routes::Match to position.
- Renamed pattern attribute in Mojolicious::Routes::Route to unparsed.
- Renamed template attribute in Mojo::Template to unparsed.
- Renamed extracting attribute in Mojo::UserAgent::CookieJar to gathering.
- Renamed extracting attribute in Mojo::UserAgent::CookieJar to collecting.
- Renamed all_contents, contents, following_siblings, next_sibling,
preceding_siblings and previous_sibling methods in Mojo::DOM to
descendant_nodes, child_nodes, following_nodes, next_node, preceding_nodes
and previous_node.
- Renamed extract and inject methods in Mojo::UserAgent::CookieJar to
nomnomnom and prepare.
- Renamed extract and inject methods in Mojo::UserAgent::CookieJar to collect
and prepare.
- Renamed inject method in Mojo::UserAgent::Proxy to prepare.
- Renamed params method in Mojo::Parameters to pairs.
- Renamed -A option of prefork command to -a.
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -254,7 +254,7 @@ sub _finish {
# Finish WebSocket
return $self->_remove($id, 1) if $old->is_websocket;

if (my $jar = $self->cookie_jar) { $jar->nomnomnom($old) }
if (my $jar = $self->cookie_jar) { $jar->collect($old) }

# Upgrade connection to WebSocket
if (my $new = $self->transactor->upgrade($old)) {
Expand Down Expand Up @@ -512,8 +512,8 @@ environment variable or C<10>.
Cookie jar to use for requests performed by this user agent, defaults to a
L<Mojo::UserAgent::CookieJar> object.
# Disable gathering of cookies from responses
$ua->cookie_jar->gathering(0);
# Disable collecting cookies from responses
$ua->cookie_jar->collecting(0);
# Add custom cookie to the jar
$ua->cookie_jar->add(
Expand Down
68 changes: 34 additions & 34 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -4,7 +4,7 @@ use Mojo::Base -base;
use Mojo::Cookie::Request;
use Mojo::Path;

has gathering => 1;
has collecting => 1;
has max_cookie_size => 4096;

sub add {
Expand Down Expand Up @@ -37,6 +37,29 @@ sub all {
return [map { @{$jar->{$_}} } sort keys %$jar];
}

sub collect {
my ($self, $tx) = @_;

return unless $self->collecting;

my $url = $tx->req->url;
for my $cookie (@{$tx->res->cookies}) {

# Validate domain
my $host = $url->ihost;
my $domain = lc($cookie->domain // $cookie->origin($host)->origin);
$domain =~ s/^\.//;
next
if $host ne $domain && ($host !~ /\Q.$domain\E$/ || $host =~ /\.\d+$/);

# Validate path
my $path = $cookie->path // $url->path->to_dir->to_abs_string;
$path = Mojo::Path->new($path)->trailing_slash(0)->to_abs_string;
next unless _path($path, $url->path->to_abs_string);
$self->add($cookie->path($path));
}
}

sub empty { delete shift->{jar} }

sub find {
Expand Down Expand Up @@ -72,29 +95,6 @@ sub find {
return \@found;
}

sub nomnomnom {
my ($self, $tx) = @_;

return unless $self->gathering;

my $url = $tx->req->url;
for my $cookie (@{$tx->res->cookies}) {

# Validate domain
my $host = $url->ihost;
my $domain = lc($cookie->domain // $cookie->origin($host)->origin);
$domain =~ s/^\.//;
next
if $host ne $domain && ($host !~ /\Q.$domain\E$/ || $host =~ /\.\d+$/);

# Validate path
my $path = $cookie->path // $url->path->to_dir->to_abs_string;
$path = Mojo::Path->new($path)->trailing_slash(0)->to_abs_string;
next unless _path($path, $url->path->to_abs_string);
$self->add($cookie->path($path));
}
}

sub prepare {
my ($self, $tx) = @_;
return unless keys %{$self->{jar}};
Expand Down Expand Up @@ -148,12 +148,12 @@ L<Mojo::UserAgent> and based on L<RFC 6265|http://tools.ietf.org/html/rfc6265>.
L<Mojo::UserAgent::CookieJar> implements the following attributes.
=head2 gathering
=head2 collecting
my $bool = $jar->gathering;
$jar = $jar->gathering($bool);
my $bool = $jar->collecting;
$jar = $jar->collecting($bool);
Allow L</"nomnomnom"> to L</"add"> new cookies to the jar, defaults to a true
Allow L</"collect"> to L</"add"> new cookies to the jar, defaults to a true
value.
=head2 max_cookie_size
Expand Down Expand Up @@ -184,6 +184,12 @@ jar.
# Names of all cookies
say $_->name for @{$jar->all};
=head2 collect
$jar->collect(Mojo::Transaction::HTTP->new);
Collect response cookies from transaction.
=head2 empty
$jar->empty;
Expand All @@ -199,12 +205,6 @@ Find L<Mojo::Cookie::Request> objects in the jar for L<Mojo::URL> object.
# Names of all cookies found
say $_->name for @{$jar->find(Mojo::URL->new('http://example.com/foo'))};
=head2 nomnomnom
$jar->nomnomnom(Mojo::Transaction::HTTP->new);
Consume response cookies from transaction.
=head2 prepare
$jar->prepare(Mojo::Transaction::HTTP->new);
Expand Down
16 changes: 8 additions & 8 deletions t/mojo/cookiejar.t
Expand Up @@ -308,7 +308,7 @@ my $tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://mojolicio.us/perldoc/Mojolicious');
$tx->res->cookies(
Mojo::Cookie::Response->new(name => 'foo', value => 'without'));
$jar->nomnomnom($tx);
$jar->collect($tx);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://mojolicio.us/perldoc');
$jar->prepare($tx);
Expand Down Expand Up @@ -340,7 +340,7 @@ $tx->res->cookies(
domain => 'example.com'
)
);
$jar->nomnomnom($tx);
$jar->collect($tx);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://example.com/test');
$jar->prepare($tx);
Expand Down Expand Up @@ -374,7 +374,7 @@ $tx->res->cookies(
domain => 'bar.localhost'
)
);
$jar->nomnomnom($tx);
$jar->collect($tx);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://localhost:8080');
$jar->prepare($tx);
Expand Down Expand Up @@ -406,7 +406,7 @@ $tx->res->cookies(
path => '/%70erldoc/Mojolicious/'
),
);
$jar->nomnomnom($tx);
$jar->collect($tx);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://labs.bücher.COM/perldoc/Mojolicious/Lite');
$jar->prepare($tx);
Expand Down Expand Up @@ -443,7 +443,7 @@ $tx->res->cookies(
),
Mojo::Cookie::Response->new(name => 'bar', value => 'too')
);
$jar->nomnomnom($tx);
$jar->collect($tx);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://213.133.102.53/perldoc/Mojolicious');
$jar->prepare($tx);
Expand All @@ -468,7 +468,7 @@ $tx->res->cookies(
domain => 'mojolicio.us'
)
);
$jar->nomnomnom($tx);
$jar->collect($tx);
is_deeply $jar->all, [], 'no cookies';

# Gather cookies with invalid domain (IP address)
Expand Down Expand Up @@ -497,7 +497,7 @@ $tx->res->cookies(
domain => '53'
)
);
$jar->nomnomnom($tx);
$jar->collect($tx);
is_deeply $jar->all, [], 'no cookies';

# Gather cookies with invalid path
Expand All @@ -521,7 +521,7 @@ $tx->res->cookies(
path => '/perldoc.Mojolicious'
)
);
$jar->nomnomnom($tx);
$jar->collect($tx);
is_deeply $jar->all, [], 'no cookies';

done_testing();
8 changes: 4 additions & 4 deletions t/mojolicious/group_lite_app.t
Expand Up @@ -284,15 +284,15 @@ my $hmac = $session->clone->hmac_sha1_sum($t->app->secrets->[0]);
$t->get_ok('/bridge2stash' => {Cookie => "mojolicious=$session--$hmac"})
->status_is(200)->content_is("stash too!!!!!!!!\n");

# Not gathering cookies
$t->reset_session->ua->cookie_jar->gathering(0);
# Not collecting cookies
$t->reset_session->ua->cookie_jar->collecting(0);
$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200)
->content_is("stash too!!!!!!!!\n");

# Still not gathering cookies
# Still not collecting cookies
$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200)
->content_is("stash too!!!!!!!!\n");
$t->ua->cookie_jar->gathering(1);
$t->ua->cookie_jar->collecting(1);

# Fresh start without cookies, session or flash
$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200)
Expand Down

0 comments on commit fdffd33

Please sign in to comment.