Debian Codegraph @

third_party/rust/viaduct/src/settings.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 use once_cell::sync::Lazy;
6 use parking_lot::RwLock;
7 use std::time::Duration;
8 use url::Url;
9
10 /// Note: reqwest allows these only to be specified per-Client. concept-fetch
11 /// allows these to be specified on each call to fetch. I think it's worth
12 /// keeping a single global reqwest::Client in the reqwest backend, to simplify
13 /// the way we abstract away from these.
14 ///
15 /// In the future, should we need it, we might be able to add a CustomClient type
16 /// with custom settings. In the reqwest backend this would store a Client, and
17 /// in the concept-fetch backend it would only store the settings, and populate
18 /// things on the fly.
19 #[derive(Debug)]
20 #[non_exhaustive]
21 pub struct Settings {
22 pub read_timeout: Option<Duration>,
23 pub connect_timeout: Option<Duration>,
24 pub follow_redirects: bool,
25 pub use_caches: bool,
26 // For testing purposes, we allow exactly one additional Url which is
27 // allowed to not be https.
28 pub addn_allowed_insecure_url: Option<Url>,
29 }
30
31 #[cfg(target_os = "ios")]
32 const TIMEOUT_DURATION: Duration = Duration::from_secs(7);
33
34 #[cfg(not(target_os = "ios"))]
35 const TIMEOUT_DURATION: Duration = Duration::from_secs(10);
36
37 // The singleton instance of our settings.
38 pub static GLOBAL_SETTINGS: Lazy<RwLock<Settings>> = Lazy::new(|| {
39 RwLock::new(Settings {
40 read_timeout: Some(TIMEOUT_DURATION),
41 connect_timeout: Some(TIMEOUT_DURATION),
42 follow_redirects: true,
43 use_caches: false,
44 addn_allowed_insecure_url: None,
45 })
46 });