Skip to main content

qubit_http/
constants.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026.
4 *    Haixing Hu, Qubit Co. Ltd.
5 *
6 *    All rights reserved.
7 *
8 ******************************************************************************/
9//! Crate-wide defaults and fixed tuning values for HTTP client behavior and logging.
10
11// ---------------------------------------------------------------------------
12// Sensitive headers (log masking)
13// ---------------------------------------------------------------------------
14
15/// Built-in header names preloaded into [`crate::SensitiveHttpHeaders::default`]
16/// for log masking.
17pub const DEFAULT_SENSITIVE_HEADER_NAMES: [&str; 21] = [
18    "Authorization",
19    "Proxy-Authorization",
20    "Api-Key",
21    "X-Api-Key",
22    "Bearer",
23    "Cookie",
24    "Set-Cookie",
25    "Secret-Key",
26    "Client-Secret",
27    "Access-Token",
28    "Refresh-Token",
29    "Private-Token",
30    "Session-Token",
31    "JWT-Token",
32    "Password",
33    "X-Auth-Password",
34    "X-Client-ID",
35    "X-Client-Secret",
36    "X-Auth-Token",
37    "X-Auth-App-Token",
38    "X-Auth-User-Token",
39];
40
41// ---------------------------------------------------------------------------
42// Timeouts ([`crate::HttpTimeoutOptions::default`])
43// ---------------------------------------------------------------------------
44
45/// Default connect timeout in seconds.
46pub const DEFAULT_CONNECT_TIMEOUT_SECS: u64 = 10;
47
48/// Default read timeout in seconds.
49pub const DEFAULT_READ_TIMEOUT_SECS: u64 = 120;
50
51/// Default write timeout in seconds.
52pub const DEFAULT_WRITE_TIMEOUT_SECS: u64 = 120;
53
54// ---------------------------------------------------------------------------
55// Logging ([`crate::HttpLoggingOptions::default`])
56// ---------------------------------------------------------------------------
57
58/// Default maximum body bytes included in TRACE log previews.
59pub const DEFAULT_LOG_BODY_SIZE_LIMIT_BYTES: usize = 16 * 1024;
60
61/// Default maximum bytes included in non-success response body previews on [`crate::HttpError`].
62pub const DEFAULT_ERROR_RESPONSE_PREVIEW_LIMIT_BYTES: usize = 16 * 1024;
63
64// ---------------------------------------------------------------------------
65// SSE decode safety limits
66// ---------------------------------------------------------------------------
67
68/// Default maximum bytes allowed for a single SSE line before raising a protocol error.
69pub const DEFAULT_SSE_MAX_LINE_BYTES: usize = 64 * 1024;
70
71/// Default maximum bytes allowed for one SSE frame (between blank lines) before raising a protocol error.
72pub const DEFAULT_SSE_MAX_FRAME_BYTES: usize = 1024 * 1024;
73
74// ---------------------------------------------------------------------------
75// Sensitive header value masking rules used by [`crate::HttpLogger`]
76// ---------------------------------------------------------------------------
77
78/// Values with at most this many characters are fully replaced by [`SENSITIVE_HEADER_MASK_PLACEHOLDER`].
79pub const SENSITIVE_HEADER_MASK_SHORT_LEN: usize = 4;
80
81/// How many characters to keep visible at the start and end when masking longer values.
82pub const SENSITIVE_HEADER_MASK_EDGE_CHARS: usize = 2;
83
84/// Replacement string for fully masked or middle segments of sensitive header values.
85pub const SENSITIVE_HEADER_MASK_PLACEHOLDER: &str = "****";