Revert "http/https proxy (#7600)" (#7801)

This reverts commit da57fcb641.
This commit is contained in:
RustDesk
2024-04-23 15:26:16 +08:00
committed by GitHub
parent da57fcb641
commit ac7f8a6447
68 changed files with 133 additions and 1231 deletions

View File

@@ -1,5 +1,4 @@
use super::HbbHttpResponse;
use crate::hbbs_http::create_http_client;
use hbb_common::{config::LocalConfig, log, ResultType};
use reqwest::blocking::Client;
use serde_derive::{Deserialize, Serialize};
@@ -131,7 +130,7 @@ impl Default for UserStatus {
impl OidcSession {
fn new() -> Self {
Self {
client: create_http_client(),
client: Client::new(),
state_msg: REQUESTING_ACCOUNT_AUTH,
failed_msg: "".to_owned(),
code_url: None,
@@ -169,7 +168,7 @@ impl OidcSession {
id: &str,
uuid: &str,
) -> ResultType<HbbHttpResponse<AuthBody>> {
let url = Url::parse_with_params(
let url = reqwest::Url::parse_with_params(
&format!("{}/api/oidc/auth-query", api_server),
&[("code", code), ("id", id), ("uuid", uuid)],
)?;

View File

@@ -1,71 +0,0 @@
use hbb_common::config::Config;
use hbb_common::log::info;
use hbb_common::proxy::{Proxy, ProxyScheme};
use reqwest::blocking::Client as SyncClient;
use reqwest::Client as AsyncClient;
macro_rules! configure_http_client {
($builder:expr, $Client: ty) => {{
let mut builder = $builder;
let client = if let Some(conf) = Config::get_socks() {
let proxy_result = Proxy::from_conf(&conf, None);
match proxy_result {
Ok(proxy) => {
let proxy_setup = match &proxy.intercept {
ProxyScheme::Http { host, .. } =>{ reqwest::Proxy::http(format!("http://{}", host))},
ProxyScheme::Https { host, .. } => {reqwest::Proxy::https(format!("https://{}", host))},
ProxyScheme::Socks5 { addr, .. } => { reqwest::Proxy::all(&format!("socks5://{}", addr)) }
};
match proxy_setup {
Ok(p) => {
builder = builder.proxy(p);
if let Some(auth) = proxy.intercept.maybe_auth() {
let basic_auth =
format!("Basic {}", auth.get_basic_authorization());
builder = builder.default_headers(
vec![(
reqwest::header::PROXY_AUTHORIZATION,
basic_auth.parse().unwrap(),
)]
.into_iter()
.collect(),
);
}
builder.build().unwrap_or_else(|e| {
info!("Failed to create a proxied client: {}", e);
<$Client>::new()
})
}
Err(e) => {
info!("Failed to set up proxy: {}", e);
<$Client>::new()
}
}
}
Err(e) => {
info!("Failed to configure proxy: {}", e);
<$Client>::new()
}
}
} else {
builder.build().unwrap_or_else(|e| {
info!("Failed to create a client: {}", e);
<$Client>::new()
})
};
client
}};
}
pub fn create_http_client() -> SyncClient {
let builder = SyncClient::builder();
configure_http_client!(builder, SyncClient)
}
pub fn create_http_client_async() -> AsyncClient {
let builder = AsyncClient::builder();
configure_http_client!(builder, AsyncClient)
}

View File

@@ -1,4 +1,3 @@
use crate::hbbs_http::create_http_client;
use bytes::Bytes;
use hbb_common::{bail, config::Config, lazy_static, log, ResultType};
use reqwest::blocking::{Body, Client};
@@ -26,7 +25,7 @@ pub fn is_enable() -> bool {
pub fn run(rx: Receiver<RecordState>) {
let mut uploader = RecordUploader {
client: create_http_client(),
client: Client::new(),
api_server: crate::get_api_server(
Config::get_option("api-server"),
Config::get_option("custom-rendezvous-server"),