Skip to content

Commit b1dbee2

Browse files
authored
fix(http): manually set origin header to tauri://localhost (#3210)
1 parent d7a0bb3 commit b1dbee2

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

.changes/fix-http-origin.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
http: patch
3+
http-js: patch
4+
---
5+
6+
Fixed an issue that caused the Origin header to always be `null` on macOS, iOS and Linux.

plugins/http/src/commands.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ pub async fn fetch<R: Runtime>(
279279

280280
if headers.contains_key(header::RANGE) {
281281
// https://fetch.spec.whatwg.org/#http-network-or-cache-fetch step 18
282-
// If httpRequests header list contains `Range`, then append (`Accept-Encoding`, `identity`)
282+
// If httpRequest's header list contains `Range`, then append (`Accept-Encoding`, `identity`)
283283
headers.append(header::ACCEPT_ENCODING, HeaderValue::from_str("identity")?);
284284
}
285285

@@ -290,10 +290,13 @@ pub async fn fetch<R: Runtime>(
290290
// ensure we have an Origin header set
291291
if cfg!(not(feature = "unsafe-headers")) || !headers.contains_key(header::ORIGIN) {
292292
if let Ok(url) = webview.url() {
293-
headers.append(
294-
header::ORIGIN,
295-
HeaderValue::from_str(&url.origin().ascii_serialization())?,
296-
);
293+
// The url crate returns OpaqueOrigin for tauri://localhost which serializes to "null"
294+
let origin = if url.scheme() == "tauri" {
295+
"tauri://localhost".to_string()
296+
} else {
297+
url.origin().ascii_serialization()
298+
};
299+
headers.append(header::ORIGIN, HeaderValue::from_str(&origin)?);
297300
}
298301
}
299302

0 commit comments

Comments
 (0)