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 21, 2024
1 parent 80c91a1 commit 573c46b
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 23 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
9 changes: 8 additions & 1 deletion server/src/bin/crawl-worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,14 @@ 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().map_err(|_| {
ServiceError::InternalServerError(
"Failed to acquire tls connection".to_string()
)
})?))
.build()
.get(&url)
.call()
.map_err(|e| ServiceError::InternalServerError(format!("Failed to fetch: {}", e)))?
.into_json()
Expand Down
Loading

0 comments on commit 573c46b

Please sign in to comment.