Created
February 11, 2015 10:12
-
-
Save dakkar/5645bb54bdfa1ede08fa to your computer and use it in GitHub Desktop.
Test case for Plack::Middleware::Session issue #29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
use strict; | |
use warnings; | |
package ForceSessionSave { | |
use parent 'Plack::Middleware'; | |
sub call { | |
my ($self,$env) = @_; | |
my $res = $self->app->($env); | |
$self->response_cb( | |
$res, | |
sub { | |
delete $env->{'psgix.session.cleanup'}; | |
return; | |
}, | |
); | |
} | |
}; | |
$INC{'ForceSessionSave.pm'}=__FILE__; | |
use Plack::Builder; | |
use Plack::Response; | |
use Plack::Session::Store::DBI; | |
use DBI; | |
use Data::Dump 'pp'; | |
my $app = sub { | |
my ($env) = @_; | |
my $counter = $env->{'psgix.session'}{counter}//0; | |
my $path = $env->{PATH_INFO}; | |
my ($path_counter) = $path =~ m{now(\d+)$}; | |
warn "session: $counter, path: $path ($path_counter)"; | |
if ($counter<3) { | |
if ($counter>0) { | |
if ($path_counter != $counter) { | |
warn "got $path_counter, expected $counter"; | |
} | |
} | |
++$counter; | |
$env->{'psgix.session'}{counter}=$counter; | |
my $res = Plack::Response->new(); | |
$res->redirect("/now$counter"); | |
return $res->finalize; | |
} | |
else { | |
return [ | |
200, | |
['Content-type' => 'text/plain'], | |
[pp $env], | |
]; | |
} | |
}; | |
builder { | |
# without this, things break | |
enable '+ForceSessionSave'; | |
enable Session => ( | |
store => Plack::Session::Store::DBI->new( | |
get_dbh => sub { | |
DBI->connect('dbi:Pg:dbname=sessiontest','','',{AutoCommit=>1}) | |
}, | |
), | |
state => 'Cookie', | |
); | |
$app; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plackup -s Starman --nproc 5 --workers 5 app.psgi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
my $ua = LWP::UserAgent->new( | |
cookie_jar => {}, | |
); | |
my $res = $ua->get('http://localhost:5000'); | |
print $res->as_string; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment