Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@s-aska
Created December 14, 2010 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-aska/740216 to your computer and use it in GitHub Desktop.
Save s-aska/740216 to your computer and use it in GitHub Desktop.
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