@@ -17,8 +17,9 @@ BEGIN {
17
17
use Config::JFDI;
18
18
use FindBin;
19
19
use lib " $FindBin::RealBin /lib" ;
20
- use File::Path ();
21
- use JSON qw( encode_json decode_json ) ;
20
+ use File::Path ();
21
+ use JSON ();
22
+ use MIME::Base64 ();
22
23
use MetaCPAN::Web;
23
24
use Plack::Builder;
24
25
use Plack::App::File;
@@ -31,6 +32,7 @@ use Plack::Middleware::ReverseProxy;
31
32
use Plack::Middleware::Session::Cookie;
32
33
use Plack::Middleware::ServerStatus::Lite;
33
34
use Plack::Session::Store::File;
35
+ use Try::Tiny;
34
36
35
37
# explicitly call ->to_app on every Plack::App::* for performance
36
38
my $app = Plack::App::URLMap-> new;
@@ -65,9 +67,6 @@ my $app = Plack::App::URLMap->new;
65
67
66
68
die ' cookie_secret not configured' unless $config -> get-> {cookie_secret };
67
69
68
- my $storage_path = " $path /var/tmp/cookies" ;
69
- maybe_make_path($storage_path );
70
-
71
70
# Add session cookie here only
72
71
$core_app = Plack::Middleware::Session::Cookie-> wrap(
73
72
$core_app ,
@@ -76,11 +75,22 @@ my $app = Plack::App::URLMap->new;
76
75
secure => ( ( $ENV {PLACK_ENV } || q[ ] ) ne ' development' ),
77
76
httponly => 1,
78
77
secret => $config -> get-> {cookie_secret },
79
- store => Plack::Session::Store::File-> new(
80
- dir => $storage_path ,
81
- serializer => sub { encode_json(@_ ) },
82
- deserializer => sub { decode_json(@_ ) },
83
- ),
78
+ serializer => sub {
79
+
80
+ # Pass $_[0] since the json subs may have a ($) protoype.
81
+ # Pass '' to base64 for a blank separator (instead of newlines).
82
+ MIME::Base64::encode( JSON::encode_json( $_ [0] ), q[ ] );
83
+ },
84
+ deserializer => sub {
85
+
86
+ # Use try/catch so JSON doesn't barf if the cookie is bad.
87
+ try {
88
+ JSON::decode_json( MIME::Base64::decode( $_ [0] ) )
89
+ }
90
+
91
+ # No session.
92
+ catch { +{}; };
93
+ },
84
94
);
85
95
86
96
$app -> map ( q[ /] => $core_app );
0 commit comments