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

[bug] audio tag using a asset resource file as the source, the asset server returns wrong content-type of text/html #5203

Closed
nathanfaucett opened this issue Sep 15, 2022 · 5 comments
Labels
platform: macOS platform: Windows priority: 3 low scope: core Core packages of Tauri status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@nathanfaucett
Copy link

nathanfaucett commented Sep 15, 2022

Describe the bug

audio tag using a asset resource file as the source, the asset server returns wrong content-type of text/html

Reproduction

create project with audio files in bundle.resources create a filepath using something like

const filePath = convertFileSrc(
	await normalize(
		await resolveResource('name_of_audio_file.mp3')
	)
)

use in audio tag <audio controls><source src="{filePath}" type="audio/mpeg" /></audio>

Screen Shot 2022-09-15 at 16 53 31

Expected behavior

the content type to be audio/mpeg

Platform and versions

Environment
› OS: Mac OS 12.2.1 X64
› Node.js: 16.15.0
› npm: 8.8.0
› pnpm: 7.0.0
› yarn: Not installed!
› rustup: 1.25.1
› rustc: 1.63.0
› cargo: 1.63.0
› Rust toolchain: stable-aarch64-apple-darwin

Packages
› @tauri-apps/cli [NPM]: 1.1.0
› @tauri-apps/api [NPM]: 1.1.0
› tauri [RUST]: 1.1.0,
› tauri-build [RUST]: 1.1.0,
› tao [RUST]: 0.14.0,
› wry [RUST]: 0.21.0,

App
› build-type: bundle
› CSP: default-src 'self'; img-src 'self' asset: https://asset.localhost; media-src 'self' asset: https://asset.localhost;
› distDir: ../dist
› devPath: http://localhost:3000/
› framework: Svelte

App directory structure
├─ node_modules
├─ public
├─ src-tauri
├─ .git
├─ .vscode
└─ src

Stack trace

No response

Additional context

No response

@nathanfaucett nathanfaucett added status: needs triage This issue needs to triage, applied to new issues type: bug labels Sep 15, 2022
@nathanfaucett nathanfaucett changed the title [bug] audio tag using a asset resource file as the source, the asset server returns wrong content-type of html/text [bug] audio tag using a asset resource file as the source, the asset server returns wrong content-type of text/html Sep 15, 2022
@Moon1102
Copy link

Moon1102 commented Sep 16, 2022

Maybe the good news is that it doesn't affect playback :) (yes! also can work in production mode)

图片

The code is not complicated in Vue3.
图片

@amrbashir amrbashir added scope: core Core packages of Tauri priority: 3 low status: needs triage This issue needs to triage, applied to new issues platform: Windows platform: macOS and removed status: needs triage This issue needs to triage, applied to new issues labels Sep 16, 2022
@amrbashir
Copy link
Member

amrbashir commented Sep 16, 2022

This only affects requests with range header. Initial request seems fine, only subsequent requests are affected.

This is probably because in the initial request we are reading the first bytes of the file where it usually contains the magic number to identify the file while subsequent requests might not have the magic number inside it and so infer crate will fail to parse the correct mimetype.

@lucasfernog should we use https://docs.rs/infer/0.9.0/infer/fn.get_from_path.html instead?

@lucasfernog
Copy link
Member

We shouldn't infer the mime type from the path, that's a security vulnerability. We could instead cache the mime type on range requests or maybe always read the first bytes.

@amrbashir
Copy link
Member

get_from_path does read the first bytes, it doesn't rely on file extension. https://docs.rs/infer/0.9.0/src/infer/lib.rs.html#240-251

@amrbashir
Copy link
Member

although I think caching might be better for performance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: macOS platform: Windows priority: 3 low scope: core Core packages of Tauri status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

4 participants