Skip to content

Commit

Permalink
feature: use native-tls in ureq requests to trust system TLS certs
Browse files Browse the repository at this point in the history
  • Loading branch information
adtac committed Dec 20, 2024
1 parent a225fe3 commit 1e9d4b4
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 11 deletions.
192 changes: 192 additions & 0 deletions pdf2md/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pdf2md/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ edition = "2021"
base64 = "0.22.1"
clap = { version = "4.5.20", features = ["derive", "env"] }
serde_json = "1.0.132"
ureq = { version = "2.10.1", features = ["json"] }
ureq = { version = "2.10.1", features = ["json", "native-tls"] }
native-tls = "0.2.12"
7 changes: 6 additions & 1 deletion pdf2md/cli/src/operators/create_task.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use std::sync::Arc;

use base64::Engine;

pub fn create_task(file: &str, base_url: &str, api_key: &str) {
let file_buf = std::fs::read(file).expect("Failed to read file");
let file_base64 = base64::prelude::BASE64_STANDARD.encode(file_buf);

let request = ureq::post(format!("{}/api/task", base_url).as_str())
let request = ureq::AgentBuilder::new()
.tls_connector(Arc::new(native_tls::TlsConnector::new()?))
.build()
.post(format!("{}/api/task", base_url).as_str())
.set("Content-Type", "application/json")
.set("Authorization", api_key)
.send_json(serde_json::json!({
Expand Down
7 changes: 6 additions & 1 deletion pdf2md/cli/src/operators/poll_task.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use std::sync::Arc;

pub fn poll_task(task_id: &str, base_url: &str, api_key: &str) {
loop {
let request = ureq::get(format!("{}/api/task/{}", base_url, task_id).as_str())
let request = ureq::AgentBuilder::new()
.tls_connector(Arc::new(native_tls::TlsConnector::new()?))
.build()
.get(format!("{}/api/task/{}", base_url, task_id).as_str())
.set("Content-Type", "application/json")
.set("Authorization", api_key)
.call()
Expand Down
2 changes: 2 additions & 0 deletions server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ scraper = "0.19.0"
regex-split = "0.1.0"
simple-server-timing-header = "0.1.1"
ndarray = "0.15.6"
ureq = { version = "2.9.6", features = ["json"] }
ureq = { version = "2.9.6", features = ["json", "native-tls"] }
native-tls = "0.2.12"
env_logger = "0.11.5"
tokio-postgres = "0.7.10"
postgres-openssl = "0.5.0"
Expand Down
6 changes: 5 additions & 1 deletion server/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::error::Error;
use std::sync::Arc;

#[cfg(feature = "hallucination-detection")]
#[cfg(feature = "ner")]
Expand Down Expand Up @@ -63,7 +64,10 @@ fn download_file<P>(url: String, target_file: &P)
where
P: AsRef<Path>,
{
let resp = ureq::get(&url)
let resp = ureq::AgentBuilder::new()
.tls_connector(Arc::new(native_tls::TlsConnector::new()?))
.build()
.get(&url)
.timeout(std::time::Duration::from_secs(300))
.call()
.unwrap_or_else(|err| panic!("ERROR: Failed to download {}: {:?}", url, err));
Expand Down
5 changes: 4 additions & 1 deletion server/src/bin/crawl-worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,10 @@ async fn crawl(
let cleaned_url = crawl_request.url.trim_end_matches("/");
let url = format!("{}/products.json?page={}", cleaned_url, cur_page);

let response: ShopifyResponse = ureq::get(&url)
let response: ShopifyResponse = ureq::AgentBuilder::new()
.tls_connector(Arc::new(native_tls::TlsConnector::new()?))
.build()
.get(&url)
.call()
.map_err(|e| ServiceError::InternalServerError(format!("Failed to fetch: {}", e)))?
.into_json()
Expand Down
1 change: 1 addition & 0 deletions server/src/handlers/webhook_handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::sync::Arc;
use std::str::FromStr;

use crate::data::models::Pool;
Expand Down
Loading

0 comments on commit 1e9d4b4

Please sign in to comment.