1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! SSE keepalive wrapper — Cilium-mandatory 15s interval.
//!
//! Without a keepalive, idle SSE connections hit Cilium's connection timeout
//! and are silently dropped. All nido-*-svc SSE endpoints must use this
//! wrapper.
use ;
use Stream;
use Duration;
/// Default keepalive interval required to survive Cilium connection timeouts.
pub const SSE_KEEPALIVE_SECS: u64 = 15;
/// Wrap a stream in `Sse` with the mandatory 15-second keepalive.
///
/// # Example
///
/// ```rust,no_run
/// # use futures::stream;
/// # use axum::response::sse::Event;
/// # use std::convert::Infallible;
/// use nido_svc_common::sse::sse_with_keepalive;
///
/// async fn events_handler() -> impl axum::response::IntoResponse {
/// let stream = stream::empty::<Result<Event, Infallible>>();
/// sse_with_keepalive(stream)
/// }
/// ```