1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# /usr/bin/perl -wT
use lib ('.','./extlib2/lib/perl5');
use Plack::Request;
use Data::Dumper;
my $handler = sub {
my $env = shift;
my $req = Plack::Request->new($env);
my $cookie = $req->cookies;
my $res = Plack::Request->new_response();
if ($cookie) {
$res->status(200);
$res->headers;
$res->body(["COOKIE", Dumper $cookie, "ENV", Dumper $env]);
$res->finalize
}
else {
$res->cookies->{'session_id'}='1234';
$res->redirect("/");
$res->finalize;
}
};
1
2
3
my $cookie = $q->cookie(-name => 'session_id', -value => $self->generate_id() );
my ($status_code, $headers_aref) = $q->psgi_redirect(-cookie => $cookie, -uri => $q->self_url());
return [$status_code, [$headers_aref], [] ];
Quote127.0.0.1 - - [27/Nov/2016:08:06:25 +0100] "GET / HTTP/1.1" 200 1690 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
127.0.0.1 - - [27/Nov/2016:08:06:26 +0100] "GET /favicon.ico HTTP/1.1" 200 1593 "http://localhost:5000/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
1
2
3
4
5
# are there cookies defined? dereference the hash-reference
if ( %$cookies ) {
}
else {
}