XMLHttpRequest Send: fix Content-Type failures (#38993)

Replaced usage of `typed_insert` since it ended converting `UTF-8` to
lowercase.
Removed one of the test cases since it wasn't following spec since
[xhr/205](https://github.com/whatwg/xhr/pull/205).

Testing: Changes covered by wpt
Fixes: #20436

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This commit is contained in:
Gae24 2025-08-28 14:44:42 +02:00 committed by GitHub
parent cb64def7e6
commit 908c392219
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 7 additions and 32 deletions

View file

@ -739,7 +739,7 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
.collect(); .collect();
let new_mime = format!( let new_mime = format!(
"{}/{}; charset={}{}{}", "{}/{};charset={}{}{}",
mime.type_, mime.type_,
mime.subtype, mime.subtype,
encoding, encoding,
@ -750,9 +750,11 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("; ") .join("; ")
); );
request
.headers request.headers.insert(
.typed_insert(ContentType::from_str(&new_mime).unwrap()) header::CONTENT_TYPE,
HeaderValue::from_str(&new_mime).unwrap(),
);
} }
} }
} }

View file

@ -922538,7 +922538,7 @@
] ]
], ],
"setrequestheader-content-type.htm": [ "setrequestheader-content-type.htm": [
"07238391eb5cc8639edbe996208a18b6d9d26b04", "c78482142469cf966c3f64287c81c78bcd4f3e63",
[ [
null, null,
{ {

View file

@ -2,17 +2,11 @@
[charset given but wrong, fix it (unknown MIME, bogus charset)] [charset given but wrong, fix it (unknown MIME, bogus charset)]
expected: FAIL expected: FAIL
[charset given but wrong, fix it (known MIME, actual charset)]
expected: FAIL
[Multiple non-UTF-8 charset parameters deduplicate, bogus parameter dropped] [Multiple non-UTF-8 charset parameters deduplicate, bogus parameter dropped]
expected: FAIL expected: FAIL
[charset with leading space that is UTF-8 does change] [charset with leading space that is UTF-8 does change]
expected: FAIL expected: FAIL
[charset in double quotes with space]
expected: FAIL
[unknown parameters need to be preserved] [unknown parameters need to be preserved]
expected: FAIL expected: FAIL

View file

@ -1,12 +0,0 @@
[setrequestheader-content-type.htm]
[String request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8]
expected: FAIL
[XML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8]
expected: FAIL
[HTML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8]
expected: FAIL
[URLSearchParams request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8]
expected: FAIL

View file

@ -206,15 +206,6 @@
"application/x-www-form-urlencoded;charset=UTF-8", "application/x-www-form-urlencoded;charset=UTF-8",
'URLSearchParams request has correct default Content-Type of "application/x-www-form-urlencoded;charset=UTF-8"' 'URLSearchParams request has correct default Content-Type of "application/x-www-form-urlencoded;charset=UTF-8"'
) )
request(
function _URLSearchParams() { return new URLSearchParams("q=testQ&topic=testTopic") },
{"Content-Type": "application/xml;charset=ASCII"},
"application/xml;charset=UTF-8",
"URLSearchParams request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8"
// the default Content-Type for URLSearchParams has a charset specified (utf-8) in
// https://fetch.spec.whatwg.org/#bodyinit, so the user's must be changed to match it
// as per https://xhr.spec.whatwg.org/#the-send%28%29-method step 4.
)
</script> </script>
</body> </body>
</html> </html>