Skip to content

Commit

Permalink
added extracting attribute to Mojo::UserAgent::CookieJar
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 26, 2014
1 parent b3598d4 commit eada279
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

5.45 2014-09-27
- Added extracting attribute to Mojo::UserAgent::CookieJar.
- Improved performance of next, next_sibling, previous and previous_sibling
methods in Mojo::DOM significantly.

Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -509,8 +509,8 @@ environment variable or C<10>.
Cookie jar to use for this user agents requests, defaults to a
L<Mojo::UserAgent::CookieJar> object.
# Disable cookie jar
$ua->cookie_jar(0);
# Disable extraction of cookies from responses
$ua->cookie_jar->extracting(0);
=head2 inactivity_timeout
Expand Down
12 changes: 12 additions & 0 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -4,6 +4,7 @@ use Mojo::Base -base;
use Mojo::Cookie::Request;
use Mojo::Path;

has extracting => 1;
has max_cookie_size => 4096;

sub add {
Expand Down Expand Up @@ -40,6 +41,9 @@ sub empty { delete shift->{jar} }

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

return unless $self->extracting;

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

Expand Down Expand Up @@ -146,6 +150,14 @@ L<RFC 6265|http://tools.ietf.org/html/rfc6265>.
L<Mojo::UserAgent::CookieJar> implements the following attributes.
=head2 extracting
my $bool = $jar->extracting;
$jar = $jar->extracting(0);
Allow L</"extract"> to L</"add"> new cookies to the jar, defaults to a true
value.
=head2 max_cookie_size
my $size = $jar->max_cookie_size;
Expand Down
3 changes: 0 additions & 3 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -259,9 +259,6 @@ L<Mojolicious::Controller> and L<Mojo>.
Routing cache, defaults to a L<Mojo::Cache> object.
# Disable caching
$r->cache(0);
=head2 conditions
my $conditions = $r->conditions;
Expand Down
2 changes: 0 additions & 2 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -518,8 +518,6 @@ Render route with parameters into a path.
The L<Mojolicious::Routes> object this route is a descendant of.
$r->root->cache(0);
=head2 route
my $route = $r->route;
Expand Down
8 changes: 4 additions & 4 deletions t/mojolicious/group_lite_app.t
Expand Up @@ -288,15 +288,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");

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

# Again without cookie jar
# Still not extracting cookies
$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200)
->content_is("stash too!!!!!!!!\n");
$t->reset_session->ua->cookie_jar(Mojo::UserAgent::CookieJar->new);
$t->ua->cookie_jar->extracting(1);

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

0 comments on commit eada279

Please sign in to comment.