Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.1.1: add tls config #59

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 105 additions & 72 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions ehttp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ serde_json = { version = "1.0", optional = true }

# For compiling natively:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# ureq = { version = "2.0", default-features = false, features = ["gzip", "tls_native_certs"] }
ureq = "2.0"
ureq = { version = "2.0", default-features = false, features = ["native-tls"] }
async-channel = { version = "2.0", optional = true }
native-tls = "0.2.12"

# For compiling to web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
14 changes: 13 additions & 1 deletion ehttp/src/native.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{Request, Response};
use std::sync::Arc;

#[cfg(feature = "native-async")]
use async_channel::{Receiver, Sender};
Expand All @@ -23,7 +24,18 @@ use async_channel::{Receiver, Sender};
/// * A browser extension blocked the request (e.g. ad blocker)
/// * …
pub fn fetch_blocking(request: &Request) -> crate::Result<Response> {
let mut req = ureq::request(&request.method, &request.url);
let tls_connector = Arc::new(
native_tls::TlsConnector::builder()
.danger_accept_invalid_hostnames(request.danger_accept_invalid_hostnames)
.danger_accept_invalid_certs(request.danger_accept_invalid_certs)
.build()
.unwrap(),
);

let mut req = ureq::builder()
.tls_connector(tls_connector)
.build()
.request(&request.method, &request.url);

for (k, v) in &request.headers {
req = req.set(k, v);
Expand Down
16 changes: 14 additions & 2 deletions ehttp/src/streaming/native.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::ops::ControlFlow;
use std::sync::Arc;

use crate::Request;

Expand All @@ -9,7 +10,18 @@ pub fn fetch_streaming_blocking(
request: Request,
on_data: Box<dyn Fn(crate::Result<Part>) -> ControlFlow<()> + Send>,
) {
let mut req = ureq::request(&request.method, &request.url);
let tls_connector = Arc::new(
native_tls::TlsConnector::builder()
.danger_accept_invalid_hostnames(request.danger_accept_invalid_hostnames)
.danger_accept_invalid_certs(request.danger_accept_invalid_certs)
.build()
.unwrap(),
);

let mut req = ureq::builder()
.tls_connector(tls_connector)
.build()
.request(&request.method, &request.url);

for (k, v) in &request.headers {
req = req.set(k, v);
Expand Down Expand Up @@ -54,7 +66,7 @@ pub fn fetch_streaming_blocking(

let mut reader = resp.into_reader();
loop {
let mut buf = vec![0; 2048];
let mut buf = vec![0; 5120];
match reader.read(&mut buf) {
Ok(n) if n > 0 => {
// clone data from buffer and clear it
Expand Down
Loading
Loading