qubit_http/sse/sse_json_mode.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! Strictness for JSON parsing on SSE `data:` lines.
11//!
12
13use parse_display::FromStr as DeriveFromStr;
14use serde::{
15 Deserialize,
16 Serialize,
17};
18
19/// How to handle JSON parse failures on SSE `data:` lines.
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveFromStr)]
21#[serde(rename_all = "snake_case")]
22#[display(style = "snake_case")]
23pub enum SseJsonMode {
24 /// Skip bad chunks and continue.
25 #[from_str(regex = "(?i)lenient")]
26 Lenient,
27 /// Propagate [`crate::HttpError::sse_decode`] on first failure.
28 #[from_str(regex = "(?i)strict")]
29 Strict,
30}