mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
fix(http): manually set origin header to tauri://localhost (#3210)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
http: patch
|
||||||
|
http-js: patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed an issue that caused the Origin header to always be `null` on macOS, iOS and Linux.
|
||||||
@@ -279,7 +279,7 @@ pub async fn fetch<R: Runtime>(
|
|||||||
|
|
||||||
if headers.contains_key(header::RANGE) {
|
if headers.contains_key(header::RANGE) {
|
||||||
// https://fetch.spec.whatwg.org/#http-network-or-cache-fetch step 18
|
// https://fetch.spec.whatwg.org/#http-network-or-cache-fetch step 18
|
||||||
// If httpRequest’s header list contains `Range`, then append (`Accept-Encoding`, `identity`)
|
// If httpRequest's header list contains `Range`, then append (`Accept-Encoding`, `identity`)
|
||||||
headers.append(header::ACCEPT_ENCODING, HeaderValue::from_str("identity")?);
|
headers.append(header::ACCEPT_ENCODING, HeaderValue::from_str("identity")?);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,10 +290,13 @@ pub async fn fetch<R: Runtime>(
|
|||||||
// ensure we have an Origin header set
|
// ensure we have an Origin header set
|
||||||
if cfg!(not(feature = "unsafe-headers")) || !headers.contains_key(header::ORIGIN) {
|
if cfg!(not(feature = "unsafe-headers")) || !headers.contains_key(header::ORIGIN) {
|
||||||
if let Ok(url) = webview.url() {
|
if let Ok(url) = webview.url() {
|
||||||
headers.append(
|
// The url crate returns OpaqueOrigin for tauri://localhost which serializes to "null"
|
||||||
header::ORIGIN,
|
let origin = if url.scheme() == "tauri" {
|
||||||
HeaderValue::from_str(&url.origin().ascii_serialization())?,
|
"tauri://localhost".to_string()
|
||||||
);
|
} else {
|
||||||
|
url.origin().ascii_serialization()
|
||||||
|
};
|
||||||
|
headers.append(header::ORIGIN, HeaderValue::from_str(&origin)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user