Skip to main content

qubit_http/
constants.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//! Crate-wide defaults and fixed tuning values for HTTP client behavior and logging.
11
12pub use crate::sanitize::DEFAULT_SENSITIVE_HEADER_NAMES;
13
14// ---------------------------------------------------------------------------
15// Timeouts ([`crate::HttpTimeoutOptions::default`])
16// ---------------------------------------------------------------------------
17
18/// Default connect timeout in seconds.
19pub const DEFAULT_CONNECT_TIMEOUT_SECS: u64 = 10;
20
21/// Default read timeout in seconds.
22pub const DEFAULT_READ_TIMEOUT_SECS: u64 = 120;
23
24/// Default write timeout in seconds.
25pub const DEFAULT_WRITE_TIMEOUT_SECS: u64 = 120;
26
27// ---------------------------------------------------------------------------
28// Logging ([`crate::HttpLoggingOptions::default`])
29// ---------------------------------------------------------------------------
30
31/// Default maximum body bytes included in TRACE log previews.
32pub const DEFAULT_LOG_BODY_SIZE_LIMIT_BYTES: usize = 16 * 1024;
33
34/// Default maximum bytes included in non-success response body previews on [`crate::HttpError`].
35pub const DEFAULT_ERROR_RESPONSE_PREVIEW_LIMIT_BYTES: usize = 16 * 1024;
36
37// ---------------------------------------------------------------------------
38// SSE decode safety limits
39// ---------------------------------------------------------------------------
40
41/// Default maximum bytes allowed for a single SSE line before raising a protocol error.
42pub const DEFAULT_SSE_MAX_LINE_BYTES: usize = 64 * 1024;
43
44/// Default maximum bytes allowed for one SSE frame (between blank lines) before raising a protocol error.
45pub const DEFAULT_SSE_MAX_FRAME_BYTES: usize = 1024 * 1024;
46
47// ---------------------------------------------------------------------------
48// Sensitive header value masking rules used by [`crate::HttpLogger`]
49// ---------------------------------------------------------------------------
50
51/// Values with at most this many characters are fully replaced by [`SENSITIVE_HEADER_MASK_PLACEHOLDER`].
52pub const SENSITIVE_HEADER_MASK_SHORT_LEN: usize = 4;
53
54/// How many characters to keep visible at the start and end when masking longer values.
55pub const SENSITIVE_HEADER_MASK_EDGE_CHARS: usize = 2;
56
57/// Replacement string for fully masked or middle segments of sensitive header values.
58pub const SENSITIVE_HEADER_MASK_PLACEHOLDER: &str = "****";