Skip to content

Commit

Permalink
refactor, and change default TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalKrill committed Jun 29, 2024
1 parent 3f69943 commit ea3feec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["default-tls", "json", "msgpack", "json"]
default = ["rustls-tls", "json"]
default-tls = ["reqwest/default-tls"]
json = ["reqwest/json", "serde_json"]
rustls-tls = ["reqwest/rustls-tls"]
Expand Down
45 changes: 25 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,26 @@ impl ReqwestPlugin {

// wasm implementation
#[cfg(target_family = "wasm")]
let (tx, task) = bounded(1);

#[cfg(target_family = "wasm")]
thread_pool
.spawn(async move {
let r = client.execute(request).await;
let r = match r {
Ok(res) => {
let parts = Parts {
status: res.status(),
headers: res.headers().clone(),
};
(res.bytes().await, Some(parts))
}
Err(r) => (Err(r), None),
};
tx.send(r).ok();
})
.detach();
let task = {
let (tx, task) = bounded(1);
thread_pool
.spawn(async move {
let r = client.execute(request).await;
let r = match r {
Ok(res) => {
let parts = Parts {
status: res.status(),
headers: res.headers().clone(),
};
(res.bytes().await, Some(parts))
}
Err(r) => (Err(r), None),
};
tx.send(r).ok();
})
.detach();
task
};

// otherwise
#[cfg(not(target_family = "wasm"))]
Expand Down Expand Up @@ -175,6 +176,8 @@ impl ReqwestPlugin {
}
}
}

/// System that automatically adds a name to http request entites if they are unnamed
fn add_name_to_requests(
mut commands: Commands,
requests_without_name: Query<(Entity, &ReqRequest), (Added<ReqRequest>, Without<Name>)>,
Expand All @@ -186,7 +189,9 @@ impl ReqwestPlugin {

let url = request.url().path().to_string();

commands.entity(entity).insert(Name::new(url));
commands
.entity(entity)
.insert(Name::new(format!("http: {url}")));
}
}
}
Expand Down

0 comments on commit ea3feec

Please sign in to comment.