qubit_http/options/proxy_type.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9
10use parse_display::FromStr as DeriveFromStr;
11use serde::{Deserialize, Serialize};
12
13/// URL scheme selector used when constructing the proxy URL for reqwest.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, DeriveFromStr)]
15#[serde(rename_all = "snake_case")]
16#[display(style = "snake_case")]
17pub enum ProxyType {
18 /// HTTP proxy.
19 #[default]
20 #[display("http")]
21 #[from_str(regex = "(?i)http")]
22 Http,
23 /// HTTPS proxy.
24 #[display("https")]
25 #[from_str(regex = "(?i)https")]
26 Https,
27 /// SOCKS5 proxy.
28 #[display("socks5h")]
29 #[from_str(regex = "(?i)socks5h|socks5")]
30 Socks5,
31}
32
33impl ProxyType {
34 /// Returns the URL scheme string embedded in `proxy_url` for reqwest.
35 ///
36 /// # Parameters
37 /// - `self`: Proxy kind.
38 ///
39 /// # Returns
40 /// `"http"`, `"https"`, or `"socks5h"` (SOCKS5 with remote DNS).
41 pub fn scheme(self) -> &'static str {
42 match self {
43 ProxyType::Http => "http",
44 ProxyType::Https => "https",
45 ProxyType::Socks5 => "socks5h",
46 }
47 }
48}