Skip to content

Commit

Permalink
Do not reserialize XHR content-types unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagohirata authored and domenic committed May 28, 2019
1 parent 7cd5329 commit dd6c5a0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jsdom/living/xmlhttprequest.js
Expand Up @@ -576,8 +576,8 @@ module.exports = function createXMLHttpRequest(window) {
const charset = parsed.parameters.get("charset");
if (charset && !asciiCaseInsensitiveMatch(charset, encoding) && encoding !== null) {
parsed.parameters.set("charset", encoding);
xhrUtils.updateRequestHeader(flag.requestHeaders, "content-type", parsed.toString());
}
xhrUtils.updateRequestHeader(flag.requestHeaders, "content-type", parsed.toString());
}
}
}
Expand Down
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<title>A charset-including content-type header must not be modified (e.g. via reserialization)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
"use strict";

async_test(t => {
const xhr = new XMLHttpRequest();

xhr.open("POST", "resources/echo-content-type.py");
xhr.setRequestHeader("content-type", "application/json; charset=UTF-8");

xhr.onerror = t.unreached_func("Error occurred.");

xhr.onload = t.step_func_done(() => {
assert_equals(xhr.status, 200);
assert_equals(xhr.responseText, "application/json; charset=UTF-8");
});
xhr.send("{ \"x\":\"a\"}");
});
</script>
@@ -0,0 +1,5 @@
def main(request, response):
response.headers.set("Content-Type", "text/plain")
response.status = 200
response.content = request.headers["Content-Type"]
response.close_connection = True

0 comments on commit dd6c5a0

Please sign in to comment.