Skip to content

Instantly share code, notes, and snippets.

@bigpresh
Created February 15, 2011 22:48
Show Gist options
  • Save bigpresh/828438 to your computer and use it in GitHub Desktop.
Save bigpresh/828438 to your computer and use it in GitHub Desktop.
Dancer cookies test case
[davidp@supernova:~/tmp/dancer-multicookies]$ perl app.pl
>> Dancer 1.3010 server 25291 listening on http://0.0.0.0:4002
== Entering the development dance floor ...
[25291] debug @0.003111> [hit #1]Cookies: {
"dancer.session" => bless({ name => "dancer.session", path => "/", value => ["123, wtf"] }, "Dancer::Cookie"),
} in /usr/local/share/perl/5.10.0/Dancer/Plugin/DebugDump.pm l. 19
[davidp@supernova:~/tmp/dancer-multicookies]$ cat app.pl
#!/usr/bin/perl
# use Dancer qw(:syntax);
use Dancer;
use Dancer::Plugin::DebugDump;
setting session => 'YAML';
get '/' => sub {
debug_dump "Cookies" => cookies;
return "dancer.session is " . cookies->{'dancer.session'};
};
dance;
[davidp@supernova:~/tmp/dancer-multicookies]$ perl client.pl
GET http://localhost:4002/
User-Agent: libwww-perl/5.834
Cookie: dancer.session=123
Cookie: wtf=123
(no content)
HTTP/1.0 200 OK
Content-Type: text/html
Client-Date: Tue, 15 Feb 2011 22:46:27 GMT
Client-Peer: 127.0.0.1:4002
Client-Response-Num: 1
Set-Cookie: dancer.session=123%2C%20wtf; path=/; HttpOnly
X-Powered-By: Perl Dancer 1.3010
dancer.session is Dancer::Cookie=HASH(0xa95c3b8)
[davidp@supernova:~/tmp/dancer-multicookies]$ cat client.pl i
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use HTTP::Request;
my $host = 'localhost';
my $port = 4002;
my $ua = LWP::UserAgent->new;
$ua->add_handler("request_send", sub { shift->dump; return });
$ua->add_handler("response_done", sub { shift->dump; return });
my $request = HTTP::Request->new(GET => "http://$host:$port/");
$request->push_header(Cookie => 'dancer.session=123');
$request->push_header(Cookie => 'wtf=123');
$ua->request($request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment