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)?;