Skip to main content

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::{
13    Deserialize,
14    Serialize,
15};
16
17/// URL scheme selector used when constructing the proxy URL for reqwest.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, DeriveFromStr)]
19#[serde(rename_all = "snake_case")]
20#[display(style = "snake_case")]
21pub enum ProxyType {
22    /// HTTP proxy.
23    #[default]
24    #[display("http")]
25    #[from_str(regex = "(?i)http")]
26    Http,
27    /// HTTPS proxy.
28    #[display("https")]
29    #[from_str(regex = "(?i)https")]
30    Https,
31    /// SOCKS5 proxy.
32    #[display("socks5h")]
33    #[from_str(regex = "(?i)socks5h|socks5")]
34    Socks5,
35}
36
37impl ProxyType {
38    /// Returns the URL scheme string embedded in `proxy_url` for reqwest.
39    ///
40    /// # Parameters
41    /// - `self`: Proxy kind.
42    ///
43    /// # Returns
44    /// `"http"`, `"https"`, or `"socks5h"` (SOCKS5 with remote DNS).
45    pub fn scheme(self) -> &'static str {
46        match self {
47            ProxyType::Http => "http",
48            ProxyType::Https => "https",
49            ProxyType::Socks5 => "socks5h",
50        }
51    }
52}