Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
46b5686
feat: http asset sources
mrchantey Feb 17, 2025
56e8a64
revert from aws-lc-rs back to ring
mrchantey Apr 22, 2025
35eec21
format
mrchantey Apr 22, 2025
f102ad5
remove: allow mpl license
mrchantey Apr 22, 2025
e1f593f
Merge branch 'main' into http-asset-sources
mrchantey Apr 22, 2025
04d8fe5
format
mrchantey Apr 22, 2025
06b6d26
patch
mrchantey Apr 22, 2025
bc30b5d
Update .gitignore
mrchantey May 18, 2025
11a656d
Merge branch 'main' into http-asset-sources
mrchantey May 18, 2025
5e9f05c
lint
mrchantey May 18, 2025
0f292de
use async-fs for http_source
mrchantey May 20, 2025
06a3b6c
allow CDLA-Permissive-2.0
mrchantey May 20, 2025
bd5f778
Merge branch 'main' into http-asset-sources
mrchantey May 20, 2025
a1f4e56
Newline
alice-i-cecile May 22, 2025
de3e2b6
Merge branch 'main' into http-asset-sources
mockersf Jun 28, 2025
689c3d4
feature order
mockersf Jun 28, 2025
73999cb
Http source fixes
jf908 Jun 30, 2025
f931ab3
Forgot to undo this
jf908 Jun 30, 2025
bb156cd
Merge pull request #2 from jf908/jf908-pr-review
mrchantey Jun 30, 2025
7e4a750
update cargo features
mrchantey Jun 30, 2025
bdec2b9
Add release notes and ureq feature docs
jf908 Jun 30, 2025
93ce266
patch: not wasm
mrchantey Jul 3, 2025
0595b93
fix: get_meta_path if no extension
mrchantey Jul 4, 2025
d569fb7
Update Cargo.toml
mrchantey Jul 9, 2025
abcf04a
Update crates/bevy_asset/src/http_source.rs
mrchantey Jul 9, 2025
847ff44
Update crates/bevy_internal/Cargo.toml
mrchantey Jul 9, 2025
3afe6bd
Update docs/cargo_features.md
mrchantey Jul 9, 2025
1c93df0
Update crates/bevy_asset/src/http_source.rs
mrchantey Jul 9, 2025
4e34cdf
Update crates/bevy_asset/src/io/wasm.rs
mrchantey Jul 9, 2025
eed9948
Merge pull request #3 from jf908/jf908-pr-review
mrchantey Jul 13, 2025
2cf99ca
Use `unblock` to make http requests run on separate threads
jf908 Aug 5, 2025
3a06d05
Merge pull request #6 from jf908/async-http
mrchantey Aug 6, 2025
73d1e13
Rename anything related to http/https together as web
jf908 Aug 8, 2025
a0c3813
Remove one last reference to HttpSourceAssetReader
jf908 Aug 14, 2025
16f0ff3
Merge branch 'main' into HEAD
atlv24 Aug 17, 2025
fbf52e1
Add filters
atlv24 Aug 17, 2025
abb7227
ci
atlv24 Aug 17, 2025
1b12044
ci
atlv24 Aug 18, 2025
7286770
ci
atlv24 Aug 18, 2025
4df0bf0
Merge branch 'main' into ad/webassets
atlv24 Aug 18, 2025
eeb1f5e
Update Cargo.toml
atlv24 Aug 18, 2025
b06c522
Apply suggestions from code review
atlv24 Aug 18, 2025
e91caf1
fixes
atlv24 Aug 18, 2025
b1847eb
Remove PathFilter struct
atlv24 Aug 18, 2025
c6fbbe0
ci
atlv24 Aug 18, 2025
acc72a4
Merge branch 'main' into ad/webassets
mockersf Aug 18, 2025
51cef68
Update crates/bevy_asset/src/web.rs
atlv24 Aug 18, 2025
bc538a3
Update crates/bevy_asset/src/web.rs
atlv24 Aug 18, 2025
0f3c9bd
Update release-content/release-notes/web_assets.md
atlv24 Aug 18, 2025
a02ab99
oops
atlv24 Aug 18, 2025
0878120
Merge branch 'main' into ad/webassets
atlv24 Aug 18, 2025
d1572f7
make web asset plugin not default
atlv24 Aug 19, 2025
887b991
remove filter
atlv24 Aug 20, 2025
e4d9712
remove other bit
atlv24 Aug 28, 2025
2b0e400
Apply suggestions from code review
atlv24 Aug 28, 2025
02a9103
update note
atlv24 Aug 28, 2025
22fadcf
security warning
atlv24 Aug 28, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Cargo.lock
assets/**/*.meta
crates/bevy_asset/imported_assets
imported_assets
.web-asset-cache

# Bevy Examples
example_showcase_config.ron
Expand Down
23 changes: 22 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,15 @@ file_watcher = ["bevy_internal/file_watcher"]
# Enables watching in memory asset providers for Bevy Asset hot-reloading
embedded_watcher = ["bevy_internal/embedded_watcher"]

# Enables downloading assets from HTTP sources. Warning: there are security implications. Read the docs on WebAssetPlugin.
http = ["bevy_internal/http"]

# Enables downloading assets from HTTPS sources. Warning: there are security implications. Read the docs on WebAssetPlugin.
https = ["bevy_internal/https"]

# Enable caching downloaded assets on the filesystem. NOTE: this cache currently never invalidates entries!
web_asset_cache = ["bevy_internal/web_asset_cache"]

# Enable stepping-based debugging of Bevy systems
bevy_debug_stepping = [
"bevy_internal/bevy_debug_stepping",
Expand Down Expand Up @@ -1942,12 +1951,24 @@ path = "examples/asset/extra_source.rs"
doc-scrape-examples = true

[package.metadata.example.extra_asset_source]
name = "Extra asset source"
name = "Extra Asset Source"
description = "Load an asset from a non-standard asset source"
category = "Assets"
# Uses non-standard asset path
wasm = false

[[example]]
name = "web_asset"
path = "examples/asset/web_asset.rs"
doc-scrape-examples = true
required-features = ["https"]

[package.metadata.example.web_asset]
name = "Web Asset"
description = "Load an asset from the web"
category = "Assets"
wasm = true

[[example]]
name = "hot_asset_reloading"
path = "examples/asset/hot_asset_reloading.rs"
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ keywords = ["bevy"]
file_watcher = ["notify-debouncer-full", "watch", "multi_threaded"]
embedded_watcher = ["file_watcher"]
multi_threaded = ["bevy_tasks/multi_threaded"]
http = ["blocking", "ureq"]
https = ["blocking", "ureq", "ureq/rustls"]
web_asset_cache = []
asset_processor = []
watch = []
trace = []
Expand Down Expand Up @@ -87,6 +90,9 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.17.0-dev", default-featu

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
notify-debouncer-full = { version = "0.5.0", default-features = false, optional = true }
# updating ureq: while ureq is semver stable, it depends on rustls which is not, meaning unlikely but possible breaking changes on minor releases. https://github.com/bevyengine/bevy/pull/16366#issuecomment-2572890794
ureq = { version = "3", optional = true, default-features = false }
blocking = { version = "1.6", optional = true }

[dev-dependencies]
async-channel = "2"
Expand Down
35 changes: 32 additions & 3 deletions crates/bevy_asset/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub mod memory;
pub mod processor_gated;
#[cfg(target_arch = "wasm32")]
pub mod wasm;
#[cfg(any(feature = "http", feature = "https"))]
pub mod web;

#[cfg(test)]
pub mod gated;
Expand Down Expand Up @@ -48,7 +50,8 @@ pub enum AssetReaderError {
Io(Arc<std::io::Error>),

/// The HTTP request completed but returned an unhandled [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status).
/// If the request fails before getting a status code (e.g. request timeout, interrupted connection, etc), expect [`AssetReaderError::Io`].
/// - If the request returns a 404 error, expect [`AssetReaderError::NotFound`].
/// - If the request fails before getting a status code (e.g. request timeout, interrupted connection, etc), expect [`AssetReaderError::Io`].
#[error("Encountered HTTP status {0:?} when loading asset")]
HttpError(u16),
}
Expand Down Expand Up @@ -764,11 +767,16 @@ impl Reader for SliceReader<'_> {
}
}

/// Appends `.meta` to the given path.
/// Appends `.meta` to the given path:
/// - `foo` becomes `foo.meta`
/// - `foo.bar` becomes `foo.bar.meta`
pub(crate) fn get_meta_path(path: &Path) -> PathBuf {
let mut meta_path = path.to_path_buf();
let mut extension = path.extension().unwrap_or_default().to_os_string();
extension.push(".meta");
if !extension.is_empty() {
extension.push(".");
}
extension.push("meta");
meta_path.set_extension(extension);
meta_path
}
Expand All @@ -785,3 +793,24 @@ impl Stream for EmptyPathStream {
Poll::Ready(None)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn get_meta_path_no_extension() {
assert_eq!(
get_meta_path(Path::new("foo")).to_str().unwrap(),
"foo.meta"
);
}

#[test]
fn get_meta_path_with_extension() {
assert_eq!(
get_meta_path(Path::new("foo.bar")).to_str().unwrap(),
"foo.bar.meta"
);
}
}
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/io/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ fn js_value_to_err(context: &str) -> impl FnOnce(JsValue) -> std::io::Error + '_
}

impl HttpWasmAssetReader {
async fn fetch_bytes(&self, path: PathBuf) -> Result<impl Reader, AssetReaderError> {
// Also used by [`WebAssetReader`](crate::web::WebAssetReader)
pub(crate) async fn fetch_bytes(&self, path: PathBuf) -> Result<impl Reader, AssetReaderError> {
// The JS global scope includes a self-reference via a specializing name, which can be used to determine the type of global context available.
let global: Global = js_sys::global().unchecked_into();
let promise = if !global.window().is_undefined() {
Expand Down
Loading
Loading