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] the asset protocol should respect HEAD method and not return body #11263

Closed
chrox opened this issue Oct 7, 2024 · 0 comments
Closed

[bug] the asset protocol should respect HEAD method and not return body #11263

chrox opened this issue Oct 7, 2024 · 0 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@chrox
Copy link
Contributor

chrox commented Oct 7, 2024

Describe the bug

In the HTTP standard, a HEAD request is similar to a GET request but does not return a message body in the response.

The server sends back a 200 OK response comprised only of headers. The response is effectively metadata that describes the resource instead of the resource itself.

In the current implementation of the asset protocol, the response body includes the entire file content regardless of whether a HEAD method is used, which can result in unnecessary memory consumption in certain cases.

let buf = if let Some(b) = read_bytes {
      b
    } else {
      crate::async_runtime::safe_block_on(async move {
        let mut local_buf = Vec::with_capacity(len as usize);
        file.read_to_end(&mut local_buf).await?;
        Ok::<Vec<u8>, anyhow::Error>(local_buf)
      })?
    };
    resp = resp.header(CONTENT_LENGTH, len);
    resp.body(buf.into())

The screenshot shows the entire file content is downloaded which is not intended for the HEAD request.
screenshot-20241008-005340

Reproduction

No response

Expected behavior

It should not return the file content in the response body with HEAD request.
screenshot-20241008-005547

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.3.1 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.5.1
    - pnpm: 9.12.0
    - yarn: 1.22.22
    - npm: 10.8.2

[-] Packages
    - tauri 🦀: 2.0.2
    - tauri-build 🦀: 2.0.1
    - wry 🦀: 0.44.1
    - tao 🦀: 0.30.3
    - @tauri-apps/api : 2.0.2
    - @tauri-apps/cli : 2.0.2

[-] Plugins
    - tauri-plugin-log 🦀: 2.0.1
    - @tauri-apps/plugin-log : 2.0.0
    - tauri-plugin-http 🦀: 2.0.1
    - @tauri-apps/plugin-http : 2.0.0
    - tauri-plugin-dialog 🦀: 2.0.1
    - @tauri-apps/plugin-dialog : 2.0.0
    - tauri-plugin-os 🦀: 2.0.1
    - @tauri-apps/plugin-os : 2.0.0
    - tauri-plugin-fs 🦀: 2.0.1
    - @tauri-apps/plugin-fs : 2.0.0

[-] App
    - build-type: bundle
    - CSP: default-src 'self' ipc: http://ipc.localhost; img-src 'self' data: asset: http://asset.localhost
    - frontendDist: ../out
    - devUrl: http://localhost:3000/
    - framework: React (Next.js)
    - bundler: Webpack

Stack trace

No response

Additional context

No response

@chrox chrox added status: needs triage This issue needs to triage, applied to new issues type: bug labels Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

1 participant