From 170095b9a5829ac9279cfeea3fac0da2c922d448 Mon Sep 17 00:00:00 2001 From: SteveXMH <39523898+Steve-xmh@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:42:27 +0800 Subject: [PATCH] fix(android): skip duplicated Content-Type/Content-Length header to fix tauri-apps/tauri#8857 (#1360) * fix(android): skip duplicated Content-Type/Content-Length header to fix tauri-apps/tauri#8857 * fix(android): added comment and change log --- ...android-headers-skip-content-type-and-content-length.md | 5 +++++ src/android/binding.rs | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-android-headers-skip-content-type-and-content-length.md diff --git a/.changes/fix-android-headers-skip-content-type-and-content-length.md b/.changes/fix-android-headers-skip-content-type-and-content-length.md new file mode 100644 index 000000000..5c80c20c0 --- /dev/null +++ b/.changes/fix-android-headers-skip-content-type-and-content-length.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +Fix web resource loading in android binding by skip duplicate Content-Type/Content-Length headers. diff --git a/src/android/binding.rs b/src/android/binding.rs index 63a91400b..1a4f0af07 100644 --- a/src/android/binding.rs +++ b/src/android/binding.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT use http::{ - header::{HeaderName, HeaderValue, CONTENT_TYPE}, + header::{HeaderName, HeaderValue, CONTENT_LENGTH, CONTENT_TYPE}, Request, }; use jni::errors::Result as JniResult; @@ -216,6 +216,11 @@ fn handle_request( let response_headers = { let headers_map = JMap::from_env(env, &obj)?; for (name, value) in headers.iter() { + // WebResourceResponse will automatically generate Content-Type and + // Content-Length headers so we should skip them to avoid duplication. + if name == CONTENT_TYPE || name == CONTENT_LENGTH { + continue; + } let key = env.new_string(name)?; let value = env.new_string(value.to_str().unwrap_or_default())?; headers_map.put(env, &key, &value)?;