NAME

PAGI::Middleware::Cookie - Cookie parsing middleware

SYNOPSIS

use PAGI::Middleware::Builder;

my $app = builder {
    enable 'Cookie';
    $my_app;
};

# In your app:
async sub app {
    my ($scope, $receive, $send) = @_;

    my $cookies = $scope->{'pagi.cookies'};
    my $session_id = $cookies->{session_id};
}

DESCRIPTION

PAGI::Middleware::Cookie parses the Cookie header and makes the parsed cookies available in $scope-{'pagi.cookies'}> as a hashref.

It also provides a helper for setting response cookies.

CONFIGURATION

  • secret (optional)

    Secret key for signed cookies. Required for get_signed/set_signed.

SCOPE EXTENSIONS

This middleware adds the following to $scope:

  • pagi.cookies

    Hashref of parsed cookies from the Cookie header.

  • pagi.cookie_jar

    Object with methods for setting response cookies:

    $scope->{'pagi.cookie_jar'}->set('name', 'value',
        path     => '/',
        httponly => 1,
        secure   => 1,
        samesite => 'Strict',
        max_age  => 3600,
    );
    
    $scope->{'pagi.cookie_jar'}->delete('name');

SEE ALSO

PAGI::Middleware - Base class for middleware

PAGI::Middleware::Session - Session management using cookies