NAME

PAGI::Middleware::SSE::Retry - Add retry hints to SSE events

SYNOPSIS

use PAGI::Middleware::Builder;

my $app = builder {
    enable 'SSE::Retry',
        retry => 5000;  # 5 seconds
    $my_app;
};

DESCRIPTION

PAGI::Middleware::SSE::Retry adds the retry field to SSE events, telling clients how long to wait before reconnecting after a disconnect.

CONFIGURATION

  • retry (default: 3000)

    Default retry interval in milliseconds.

  • include_on_start (default: 1)

    If true, sends a retry hint immediately after sse.start.

  • include_on_events (default: 0)

    If true, includes retry in every sse.send event.

HOW IT WORKS

The middleware intercepts outgoing SSE events and adds the retry field. By default, a retry hint is sent immediately after sse.start to inform clients of the reconnection interval before any data events.

The retry value is in milliseconds and tells the browser's EventSource API how long to wait before attempting to reconnect after a disconnect.

SCOPE EXTENSIONS

  • pagi.sse.retry

    The configured retry interval in milliseconds.

LAST-EVENT-ID

This middleware does not handle the Last-Event-ID header for resumption. Applications should check $scope->{headers} for the Last-Event-ID header and resume from the appropriate point in the event stream.

SEE ALSO

PAGI::Middleware - Base class for middleware

PAGI::Middleware::SSE::Heartbeat - SSE keepalive comments