Skip to content

Commit

Permalink
Use an unpadded session.
Browse files Browse the repository at this point in the history
This changes the serialization method used by `Mojo::Sessions` to merely
JSON encode the session without padding.  The default serialization
method JSON encodes the session and then pads it with the letter `Z`
to a length of 1025 characaters.

This results in much smaller session cookies (roughly one fifth the
previous size).  Thus it is possible to be signed in to more courses at
a time without hitting the cookie size limit.

This should perhaps only be considered if the limit on the number of
courses that can be signed into at one time is deemed to be a big enough
problem that something needs to be done.
  • Loading branch information
drgrice1 committed Apr 6, 2024
1 parent 35c1b87 commit 5c6202c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Mojolicious/WeBWorK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Mojolicious::WeBWorK - Mojolicious app for WeBWorK 2.

use Env qw(WEBWORK_SERVER_ADMIN);

use Mojo::JSON qw(encode_json);

use WeBWorK;
use WeBWorK::CourseEnvironment;
use WeBWorK::Utils::Logs qw(writeTimingLogEntry);
Expand All @@ -41,6 +43,8 @@ sub startup ($app) {
# Configure the application
$app->secrets($config->{secrets});

$app->sessions->serialize(sub { return encode_json($_[0]) });

# Set constants from the configuration.
$WeBWorK::Debug::Enabled = $config->{debug}{enabled} // 0;
$WeBWorK::Debug::Logfile = $config->{debug}{logfile} // '';
Expand Down

0 comments on commit 5c6202c

Please sign in to comment.