Skip to content

Commit

Permalink
refactor(proxy): force using rustls_tls
Browse files Browse the repository at this point in the history
  • Loading branch information
itsusinn committed Aug 5, 2021
1 parent e18f69b commit 572261d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ bytes = "1.0.1"

# webhook
warp = "0.3.0"
reqwest = { version = "0.11.4" ,default-features = false ,features = ["rustls"] }

reqwest = { version = "0.11.4" ,default-features = false ,features = ["rustls","socks","rustls-tls-webpki-roots"] }

nats = "0.10.1"
async-nats = "0.10.1"
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod data;
mod message;
mod webhook;
mod despatch;
mod net;

use config::CONFIG;
use data::DATA;
Expand Down Expand Up @@ -53,14 +54,9 @@ async fn run() -> Result<(), anyhow::Error> {
Arc::new(Headers { inner })
};

if CONFIG.proxy.enabled {
log::info!("Proxy will be enable");
env::set_var("TELOXIDE_PROXY", &CONFIG.proxy.address);
}

let bot = Bot::with_client(
CONFIG.telegram.token.clone(),
teloxide::net::client_from_env()
net::client_from_config()
).auto_send();

let clone_header = nats_header.clone();
Expand Down
15 changes: 15 additions & 0 deletions src/net.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

fn default_reqwest_settings() -> reqwest::ClientBuilder {
teloxide_core::net::default_reqwest_settings()
}
pub fn client_from_config() -> reqwest::Client {
use crate::config::CONFIG;
let builder = default_reqwest_settings().use_rustls_tls();
if CONFIG.proxy.enabled {
builder.proxy(reqwest::Proxy::all(&CONFIG.proxy.address).expect("reqwest::Proxy creation failed"))
} else {
builder
}
.build()
.expect("creating reqwest::Client")
}

0 comments on commit 572261d

Please sign in to comment.