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