Skip to main content

docsrs_cli/config/
constants.rs

1//! Compile-time defaults, hard caps, hosts, and app identity constants.
2//!
3//! No I/O. Safe for one-shot process boot before config.toml is read.
4
5/// Default wall-clock timeout (seconds) for one operation.
6pub const DEFAULT_TIMEOUT_SECS: u64 = 30;
7/// Default TCP connect timeout (seconds).
8pub const DEFAULT_CONNECT_TIMEOUT_SECS: u64 = 10;
9/// Default maximum downloaded response body size (bytes).
10pub const DEFAULT_MAX_BODY_BYTES: u64 = 10_485_760;
11/// Hard ceiling for HTTP body size (CLI / TOML cannot raise above this).
12///
13/// Equal to [`DEFAULT_MAX_BODY_BYTES`] so operators may only lower the cap.
14/// Prevents multi-GiB allocations from untrusted Content-Length or config.
15pub const HARD_MAX_BODY_BYTES: u64 = DEFAULT_MAX_BODY_BYTES;
16/// Default maximum emitted stdout payload size (bytes).
17pub const DEFAULT_MAX_OUTPUT_BYTES: u64 = 2_097_152;
18/// Hard ceiling for emitted stdout payload size (CLI / TOML cannot raise above).
19pub const HARD_MAX_OUTPUT_BYTES: u64 = DEFAULT_MAX_OUTPUT_BYTES;
20/// Default maximum HTTP redirects followed.
21pub const DEFAULT_MAX_REDIRECTS: u32 = 5;
22/// Hard ceiling for HTTP redirects (CLI / TOML cannot raise above this).
23pub const HARD_MAX_REDIRECTS: u32 = 20;
24/// Hard ceiling for wall-clock timeout (seconds).
25pub const HARD_MAX_TIMEOUT_SECS: u64 = 600;
26/// Hard ceiling for TCP connect timeout (seconds).
27pub const HARD_MAX_CONNECT_TIMEOUT_SECS: u64 = 120;
28/// Hard ceiling for per-host politeness delay (milliseconds).
29pub const HARD_MAX_RATE_LIMIT_DELAY_MS: u64 = 60_000;
30/// Hard ceiling for on-disk `config.toml` size (poisoned-config guard).
31pub const MAX_CONFIG_TOML_BYTES: u64 = 64 * 1024;
32/// Default maximum retries for transient HTTP errors.
33pub const DEFAULT_MAX_RETRIES: u32 = crate::retry::DEFAULT_MAX_RETRIES;
34/// Base backoff delay (milliseconds) for retries.
35pub const DEFAULT_RETRY_BASE_MS: u64 = crate::retry::DEFAULT_RETRY_BASE_MS;
36/// Default ceiling for a single retry sleep (milliseconds).
37pub const DEFAULT_RETRY_MAX_DELAY_MS: u64 = crate::retry::DEFAULT_RETRY_MAX_DELAY_MS;
38/// Default total retry wall budget (`0` = derive from `timeout_secs`).
39pub const DEFAULT_RETRY_MAX_ELAPSED_MS: u64 = 0;
40/// Default minimum delay between requests to the same host (milliseconds).
41pub const DEFAULT_RATE_LIMIT_DELAY_MS: u64 = 1000;
42/// Default `tracing` filter when neither `-q` / `-v` nor `log_directive` apply.
43///
44/// Agent-first: stderr stays silent below `error` so a caller parsing stdout is
45/// never asked to skip banner noise it did not request.
46pub const DEFAULT_LOG_DIRECTIVE: &str = "error";
47/// Default `per_page` for crates.io search.
48pub const DEFAULT_PER_PAGE: u32 = 10;
49/// Default hit limit for search-in-crate.
50pub const DEFAULT_SEARCH_LIMIT: u32 = 100;
51/// Maximum `per_page` accepted for crates.io search.
52pub const MAX_PER_PAGE: u32 = 100;
53/// Maximum hit limit for search-in-crate.
54pub const MAX_SEARCH_IN_CRATE_LIMIT: u32 = 1000;
55/// Maximum query string length.
56pub const MAX_QUERY_CHARS: usize = 256;
57/// Maximum crate name length.
58pub const MAX_CRATE_NAME_CHARS: usize = 64;
59/// Maximum rustdoc item path length.
60pub const MAX_ITEM_PATH_CHARS: usize = 512;
61/// Maximum version string length.
62pub const MAX_VERSION_CHARS: usize = 64;
63/// Maximum User-Agent length.
64pub const MAX_USER_AGENT_CHARS: usize = 256;
65/// Maximum crate description length when mapping crates.io JSON → agent payload.
66///
67/// Caps hostile/oversized API strings before `max_output_bytes` emit budgeting
68/// (memory: avoid multi-MB descriptions in every hit).
69pub const MAX_CRATE_DESCRIPTION_CHARS: usize = 4_096;
70/// Maximum length for optional URL / page-token fields from crates.io JSON
71/// (`documentation`, `repository`, `homepage`, `next_page`, `prev_page`).
72pub const MAX_URL_FIELD_CHARS: usize = 2_048;
73/// Default HTTP disk cache TTL (seconds).
74pub const DEFAULT_CACHE_TTL_SECS: u64 = crate::cache::DEFAULT_CACHE_TTL_SECS;
75/// Default HTTP disk cache budget in bytes (256 MiB). `0` = unlimited.
76pub const DEFAULT_MAX_CACHE_BYTES: u64 = crate::cache::DEFAULT_MAX_CACHE_BYTES;
77/// Product binary / crate name.
78pub const APP_NAME: &str = "docsrs-cli";
79/// Package version from Cargo.
80pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
81/// Minimum supported Rust version.
82pub const MSRV: &str = "1.88.0";
83/// JSON envelope `schema_version` constant.
84pub const SCHEMA_VERSION: u32 = 1;
85
86/// crates.io host allowlist entry.
87pub const HOST_CRATES_IO: &str = "crates.io";
88/// docs.rs host allowlist entry.
89pub const HOST_DOCS_RS: &str = "docs.rs";
90/// static.docs.rs host allowlist entry (redirects).
91pub const HOST_STATIC_DOCS_RS: &str = "static.docs.rs";
92/// Official stdlib rustdoc host (`std` / `core` / `alloc`).
93pub const HOST_DOC_RUST_LANG_ORG: &str = "doc.rust-lang.org";
94/// Loopback IPv4 host (offline mocks when `allow_loopback` is true).
95pub const HOST_LOOPBACK_IPV4: &str = "127.0.0.1";
96/// Loopback hostname (offline mocks when `allow_loopback` is true).
97pub const HOST_LOCALHOST: &str = "localhost";
98/// HTTPS scheme token (product endpoints are TLS-only in production).
99pub const SCHEME_HTTPS: &str = "https";
100/// TLS port used by the `doctor --online` DNS/TCP reachability probe.
101pub const HTTPS_PORT: u16 = 443;
102/// File name of the optional XDG configuration file.
103///
104/// Four modules join this onto the config directory — loader, path reporter,
105/// `config init`, and `config path`. Renaming it in three of them would leave
106/// the fourth silently reading or reporting a file nobody writes.
107pub const CONFIG_FILE_NAME: &str = "config.toml";
108/// Historical placeholder contact host that `doctor` must reject.
109///
110/// Named here so the check and the message it prints read the same string:
111/// two literals would let one be corrected while the other kept accusing.
112pub const PLACEHOLDER_CONTACT_HOST: &str = "github.com/docsrs-cli/docsrs-cli";
113/// Default contact / repository URL (from `Cargo.toml` `[package].repository`).
114///
115/// Single source of truth — never duplicate the GitHub URL as a string literal.
116pub const DEFAULT_CONTACT_URL: &str = env!("CARGO_PKG_REPOSITORY");
117/// Delay before printing a progress hint on slow network ops (seconds).
118pub const PROGRESS_HINT_DELAY_SECS: u64 = 2;
119/// Cancel-aware sleep / flock poll step (milliseconds).
120pub const CANCEL_POLL_INTERVAL_MS: u64 = 50;