瀏覽代碼

fix(core): return empty body for HEAD requests to `asset` protocol, closes #11263 (#11264)

Huang Xin 10 月之前
父節點
當前提交
04fd3a7db5
共有 2 個文件被更改,包括 9 次插入0 次删除
  1. 5 0
      .changes/asset-protocol-head-empty-body.md
  2. 4 0
      crates/tauri/src/protocol/asset.rs

+ 5 - 0
.changes/asset-protocol-head-empty-body.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch:bug
+---
+
+Respond with empty body for `HEAD` requests to `asset` protocol

+ 4 - 0
crates/tauri/src/protocol/asset.rs

@@ -199,6 +199,10 @@ fn get_response(
       })?;
       resp.body(buf.into())
     }
+  } else if request.method() == http::Method::HEAD {
+    // if the HEAD method is used, we should not return a body
+    resp = resp.header(CONTENT_LENGTH, len);
+    resp.body(Vec::new().into())
   } else {
     // avoid reading the file if we already read it
     // as part of mime type detection