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

fix: use content-type application/octet-stream for unrecognized file types #1581

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
= 0.7.0-beta.3

== DFX

=== fix: assets with an unrecognized file extension will use content-type "application/octet-stream"

= 0.7.0-beta.2

== DFX
Expand Down
3 changes: 3 additions & 0 deletions e2e/tests-dfx/assetscanister.bash
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ CHERRIES" "$stdout"
touch src/e2e_project_assets/assets/main.css
touch src/e2e_project_assets/assets/index.js.map
touch src/e2e_project_assets/assets/index.js.LICENSE.txt
touch src/e2e_project_assets/assets/index.js.LICENSE

dfx build
dfx canister install e2e_project_assets
Expand All @@ -197,6 +198,8 @@ CHERRIES" "$stdout"
assert_match 'content_type = "text/plain"'
assert_command dfx canister call --query e2e_project_assets get '(record{key="/index.js.LICENSE.txt";accept_encodings=vec{"identity"}})'
assert_match 'content_type = "text/plain"'
assert_command dfx canister call --query e2e_project_assets get '(record{key="/index.js.LICENSE";accept_encodings=vec{"identity"}})'
assert_match 'content_type = "application/octet-stream"'
}

@test "deletes assets that are removed from project" {
Expand Down
8 changes: 1 addition & 7 deletions src/dfx/src/lib/installers/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::lib::error::{DfxError, DfxResult};
use crate::lib::waiter::waiter_with_timeout;
use candid::{CandidType, Decode, Encode, Nat};

use anyhow::anyhow;
use delay::{Delay, Waiter};
use ic_agent::Agent;
use ic_types::Principal;
Expand Down Expand Up @@ -266,12 +265,7 @@ async fn make_project_asset(

let media_type = mime_guess::from_path(&asset_location.source)
.first()
.ok_or_else(|| {
anyhow!(
"Unable to determine content type for '{}'.",
asset_location.source.to_string_lossy()
)
})?;
.unwrap_or(mime::APPLICATION_OCTET_STREAM);

let mut encodings = HashMap::new();

Expand Down