Last active
December 26, 2015 23:59
-
-
Save szabgab/7234175 to your computer and use it in GitHub Desktop.
Dancer Cookie issue
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
use Test::More tests => 6; | |
use strict; | |
use warnings; | |
# the order is important | |
use Temp; | |
use Dancer2::Test apps => ['Temp']; | |
use YAML qw(LoadFile); | |
route_exists [GET => '/'], 'a route handler is defined for /'; | |
response_status_is ['GET' => '/'], 200, 'response status is 200 for /'; | |
my $t = time; | |
my $r1 = dancer_response GET => "/set/$t"; | |
is $r1->content, "set $t"; | |
my ($cookie) = $r1->header('set-cookie') =~ /(dancer.session=[^;]+);/; | |
diag $cookie; | |
my ($id) = (split /=/, $cookie)[1]; | |
diag $id; | |
ok -e "sessions/$id.yml"; | |
my $data = LoadFile "sessions/$id.yml"; | |
is $data->{field}, $t; | |
my $r2 = dancer_response GET => "/", { | |
headers => [ | |
[ 'Cookie' => $cookie ], | |
], | |
}; | |
is $r2->content, "get $t"; |
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
# This is the main configuration file of your Dancer2 app | |
# env-related settings should go to environments/$env.yml | |
# all the settings in this file will be loaded at Dancer's startup. | |
# Your application's name | |
appname: "Temp" | |
# The default layout to use for your application (located in | |
# views/layouts/main.tt) | |
layout: "main" | |
# when the charset is set to UTF-8 Dancer2 will handle for you | |
# all the magic of encoding and decoding. You should not care | |
# about unicode within your app when this setting is set (recommended). | |
charset: "UTF-8" | |
# template engine | |
# simple: default and very basic template engine | |
# template_toolkit: TT | |
template: "simple" | |
# template: "template_toolkit" | |
# engines: | |
# template: | |
# template_toolkit: | |
# start_tag: '<%' | |
# end_tag: '%>' | |
session: YAML |
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
package Temp; | |
use Dancer2; | |
our $VERSION = '0.1'; | |
get '/' => sub { | |
return 'get ' . session('field'); | |
}; | |
get '/set/:value' => sub { | |
session field => params->{value}; | |
return 'set ' . params->{value}; | |
}; | |
true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment