Skip to main content

x_one/xhttp/
mod.rs

1//! xhttp - HTTP 客户端模块
2//!
3//! 基于 reqwest 封装,提供全局 HTTP 客户端和便捷请求方法。
4
5pub mod client;
6pub mod config;
7pub mod init;
8
9pub use client::{build_client, c, delete, get, head, patch, post, put};
10pub use config::XHttpConfig;
11
12use std::sync::atomic::{AtomicBool, Ordering};
13
14/// 幂等注册标志
15static REGISTERED: AtomicBool = AtomicBool::new(false);
16
17/// 注册 HTTP 客户端 Hook(幂等,多次调用只注册一次)
18///
19/// xhttp 仅注册 before_start,无需 before_stop(reqwest Client 可直接 drop)。
20pub fn register_hook() {
21    if REGISTERED
22        .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
23        .is_err()
24    {
25        return;
26    }
27
28    crate::before_start!(init::init_xhttp, crate::xhook::HookOptions::new().order(40));
29}