Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
app.psgi snippet
use lib qw(lib);
use Plack::Request;
use Plack::Builder;
use Plack::Session::Store::File;
use Plack::Session::State::Cookie;
use String::Urandom;
my $secure = 1; # use SSL
my $httponly = 1; # only HTTP
my $app = sub {
my $env = shift;
my $req = Plack::Request->new($env);
# ...
};
my $session_dir = '/tmp/sessions';
if (!-d $session_dir) {
mkdir $session_dir or die $!;
}
my $urandom = String::Urandom->new( LENGTH => 40 );
my $sid_generator = sub { $urandom->rand_string };
my $sid_validator = qr/\A[0-9a-zA-Z]{40}\Z/;
builder {
enable 'Session::Fixation',
store => Plack::Session::Store::File->new(
dir => $session_dir
),
state => Plack::Session::State::Cookie->new(
sid_generator => $sid_generator,
sid_validator => $sid_validator,
secure => $secure,
httponly => $httponly
);
$app;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.