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

Add http & https asset sources #16366

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0eeb08c
feat: http_source initial commit
mrchantey Nov 13, 2024
c0d3b3c
docs: update README
mrchantey Nov 13, 2024
f4cdc63
feat: http_cache_surf
mrchantey Nov 13, 2024
66046b9
docs: add backticks
mrchantey Nov 13, 2024
9160a1d
patch
mrchantey Nov 13, 2024
35b943c
fix: wasm build
mrchantey Nov 13, 2024
4c2702d
fix: wasm build
mrchantey Nov 13, 2024
f73e61f
Merge branch 'bevyengine:main' into upstream-bevy-web-asset
mrchantey Nov 17, 2024
91385f1
replace `surf` with `ureq`
mrchantey Nov 18, 2024
71d8fb2
cargo format
mrchantey Nov 18, 2024
7e9611f
rename http_source example
mrchantey Nov 18, 2024
7ca96f2
fix: asset source metadata
mrchantey Dec 6, 2024
9aa844e
fix: map ureq 404 to AssetReadError::NotFound
mrchantey Dec 6, 2024
ad69a6d
rename: WebAsseetReader > HttpSourceAssetReader
mrchantey Dec 6, 2024
a031226
build templated page
mrchantey Dec 6, 2024
777aaa9
format
mrchantey Dec 6, 2024
a82a954
refactor: reuse HttpWasmAssetReader::fetch_bytes
mrchantey Dec 6, 2024
adbfc5e
format
mrchantey Dec 6, 2024
4225cf1
patch
mrchantey Dec 6, 2024
fd8e6b3
fix: box reader
mrchantey Dec 6, 2024
3d51c1e
docs: fix references
mrchantey Dec 6, 2024
b46a410
feat: simple native asset cache
mrchantey Dec 6, 2024
dca682a
fix: clippy
mrchantey Dec 6, 2024
9c42d34
use AssertReaderError::HttpError
mrchantey Dec 7, 2024
6abb4e9
use hash instead of filename
mrchantey Dec 7, 2024
d9bd718
Merge branch 'main' into upstream-bevy-web-asset
mrchantey Dec 7, 2024
d67677f
prefer core to std
mrchantey Dec 6, 2024
1a9fae2
feat: top level `http_source` & `http_source_cache` features
mrchantey Dec 11, 2024
df8e119
fix: http_source features
mrchantey Dec 11, 2024
eb71d70
docs: update cargo features
mrchantey Dec 11, 2024
e1fc632
Add required feature for http_source example
mrchantey Dec 12, 2024
d4e72b0
Merge branch 'main' into upstream-bevy-web-asset
mockersf Dec 14, 2024
27f69f9
use example.com url
mrchantey Dec 14, 2024
5d87bb1
format
mrchantey Dec 14, 2024
0d58f97
ureq default-features=false
mrchantey Dec 18, 2024
20b6cca
allow "Unicode-3.0" & "MPL-2.0" licenses
mrchantey Dec 24, 2024
b423a92
ureq disable default features
mrchantey Dec 24, 2024
c675287
remove ureq tls feature
mrchantey Dec 24, 2024
88d04f6
docs: add license issue context
mrchantey Dec 24, 2024
b91f711
wip: rustls aws-lc-rs
mrchantey Jan 6, 2025
fa9e38d
format
mrchantey Jan 6, 2025
8b1c8ac
patch: ureq
mrchantey Jan 7, 2025
85c0615
fix: moved trait
mrchantey Jan 7, 2025
70d34a8
patch: prefer alloc
mrchantey Jan 7, 2025
8cb1118
allow: OpenSSL
mrchantey Jan 7, 2025
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
16 changes: 12 additions & 4 deletions crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ keywords = ["bevy"]
file_watcher = ["notify-debouncer-full", "watch"]
embedded_watcher = ["file_watcher"]
multi_threaded = ["bevy_tasks/multi_threaded"]
http_source = ["ureq"]
http_source = ["ureq", "rustls", "once_cell"]
http_source_cache = []
asset_processor = []
watch = []
Expand Down Expand Up @@ -65,10 +65,18 @@ js-sys = "0.3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
notify-debouncer-full = { version = "0.4.0", optional = true }
ureq = { version = "2.10", optional = true, default-features = false, features = [
"brotli",
ureq = { git = "https://github.com/algesten/ureq", rev = "fd82f2bef3c2b2a8eaeaac9aae7ea06ffe7449d3", optional = true, default-features = false, features = [
# "rustls", # compiles ok
"rustls-no-provider", # breaks compilation
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now. I'll add it to the CI.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"gzip",
# we should add tls feature when ring gets a cleaner license https://github.com/briansmith/ring/issues/1827
"json",
] }
once_cell = { version = "1.20", optional = true }
rustls = { version = "0.23", optional = true, default-features = false, features = [
"aws_lc_rs",
"logging",
"std",
"tls12",
] }

[dev-dependencies]
Expand Down
40 changes: 32 additions & 8 deletions crates/bevy_asset/src/http_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::path::{Path, PathBuf};
/// Any asset path that begins with `http` or `https` will be loaded from the web
/// via `fetch`(wasm) or `ureq`(native).
///
/// Due to [licensing complexities](https://github.com/briansmith/ring/issues/1827)
/// secure `https` requests are disabled by default in non-wasm builds.
/// Due to [licensing complexities](https://github.com/briansmith/ring/issues/1827)
/// secure `https` requests are disabled by default in non-wasm builds.
/// To enable add this to your dependencies in Cargo.toml:
/// ```toml
/// ureq = { version = "*", features = ["tls"] }
Expand Down Expand Up @@ -66,7 +66,7 @@ async fn get<'a>(path: PathBuf) -> Result<Box<dyn Reader>, AssetReaderError> {
#[cfg(not(target_arch = "wasm32"))]
async fn get<'a>(path: PathBuf) -> Result<Box<dyn Reader>, AssetReaderError> {
use crate::io::VecReader;
use std::io;
use std::io::{self, BufReader, Read};

let str_path = path.to_str().ok_or_else(|| {
AssetReaderError::Io(
Expand All @@ -82,10 +82,34 @@ async fn get<'a>(path: PathBuf) -> Result<Box<dyn Reader>, AssetReaderError> {
if let Some(data) = http_asset_cache::try_load_from_cache(str_path)? {
return Ok(Box::new(VecReader::new(data)));
}
use once_cell::sync::Lazy;
use ureq::Agent;

static AGENT: Lazy<Agent> = Lazy::new(|| {
use std::sync::Arc;
use ureq::{
tls::{TlsConfig, TlsProvider},
Agent,
};

let crypto = Arc::new(rustls::crypto::aws_lc_rs::default_provider());
Agent::config_builder()
.tls_config(
TlsConfig::builder()
.provider(TlsProvider::Rustls)
// requires rustls or rustls-no-provider feature
.unversioned_rustls_crypto_provider(crypto)
.build(),
)
.build()
.new_agent()
});

match AGENT.get(str_path).call() {
Ok(mut response) => {
// let mut reader = response.into_reader();
let mut reader = BufReader::new(response.body_mut().with_config().reader());

match ureq::get(str_path).call() {
Ok(response) => {
let mut reader = response.into_reader();
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer)?;

Expand All @@ -95,14 +119,14 @@ async fn get<'a>(path: PathBuf) -> Result<Box<dyn Reader>, AssetReaderError> {
Ok(Box::new(VecReader::new(buffer)))
}
// ureq considers all >=400 status codes as errors
Err(ureq::Error::Status(code, _response)) => {
Err(ureq::Error::StatusCode(code)) => {
if code == 404 {
mrchantey marked this conversation as resolved.
Show resolved Hide resolved
Err(AssetReaderError::NotFound(path))
} else {
Err(AssetReaderError::HttpError(code))
mrchantey marked this conversation as resolved.
Show resolved Hide resolved
}
}
Err(ureq::Error::Transport(err)) => Err(AssetReaderError::Io(
Err(err) => Err(AssetReaderError::Io(
io::Error::new(
io::ErrorKind::Other,
format!(
Expand Down
Loading