nym_http_api_client/
registry.rs1use crate::ReqwestClientBuilder;
7
8pub struct ConfigRecord {
13 pub priority: i32,
15 pub apply: fn(ReqwestClientBuilder) -> ReqwestClientBuilder,
17}
18
19inventory::collect!(ConfigRecord);
20
21pub fn default_builder() -> ReqwestClientBuilder {
23 let mut b = ReqwestClientBuilder::new();
24
25 #[cfg(feature = "debug-inventory")]
26 let mut test_client = ReqwestClientBuilder::new();
27
28 let mut records: Vec<&'static ConfigRecord> =
29 inventory::iter::<ConfigRecord>.into_iter().collect();
30 records.sort_by_key(|r| r.priority); #[cfg(feature = "debug-inventory")]
33 {
34 eprintln!(
35 "[HTTP-INVENTORY] Building client with {} registered configurations",
36 records.len()
37 );
38 }
39
40 for r in records {
41 b = (r.apply)(b);
42 #[cfg(feature = "debug-inventory")]
43 {
44 test_client = (r.apply)(test_client);
45 }
46 }
47
48 #[cfg(feature = "debug-inventory")]
49 {
50 eprintln!("[HTTP-INVENTORY] Final builder state (Debug):");
51 eprintln!("{:#?}", b);
52 eprintln!(
53 "[HTTP-INVENTORY] Note: reqwest::ClientBuilder doesn't expose all internal state"
54 );
55 eprintln!("[HTTP-INVENTORY] Building test client to verify configuration...");
56
57 match test_client.build() {
59 Ok(client) => {
60 eprintln!("[HTTP-INVENTORY] ✓ Client built successfully");
61 eprintln!("[HTTP-INVENTORY] Client debug info: {:#?}", client);
62 }
63 Err(e) => {
64 eprintln!("[HTTP-INVENTORY] ✗ Failed to build client: {}", e);
65 }
66 }
67 }
68
69 b
70}
71
72pub fn build_client() -> reqwest::Result<reqwest::Client> {
74 default_builder().build()
75}
76
77pub fn inspect_registered_configs() -> Vec<(i32, usize)> {
80 let mut configs: Vec<(i32, usize)> = inventory::iter::<ConfigRecord>
81 .into_iter()
82 .map(|record| (record.priority, record.apply as usize))
83 .collect();
84 configs.sort_by_key(|(priority, _)| *priority);
85 configs
86}
87
88pub fn debug_print_inventory() {
91 eprintln!("[HTTP-INVENTORY] Registered configurations:");
92 let configs = inspect_registered_configs();
93 if configs.is_empty() {
94 eprintln!(" (none)");
95 } else {
96 for (i, (priority, ptr)) in configs.iter().enumerate() {
97 eprintln!(
98 " [{:2}] Priority: {:4}, Function: 0x{:016x}",
99 i, priority, ptr
100 );
101 }
102 eprintln!(" Total: {} configurations", configs.len());
103 }
104}
105
106pub fn registered_config_count() -> usize {
108 inventory::iter::<ConfigRecord>.into_iter().count()
109}