Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/pythonmonkey/builtin_modules/XMLHttpRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget
}
// step 8.4
this.#responseObject = jsonObject;
return this.#responseObject;
}

// step 6 and step 7 ("blob" or "document") are not supported
Expand Down
32 changes: 32 additions & 0 deletions tests/python/test_xhr.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,37 @@ async def async_fn():
result_json = json.loads(post_result)
assert result_json["fromPM"] == "snakesandmonkeys"
assert result_json["User-Agent"].startswith("Python/")

# responseType 'json': the first read of response returns the parsed object, later reads the same one
json_result = await pm.eval("""
new Promise(function (resolve, reject)
{
let xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:4001');
xhr.responseType = 'json';

xhr.onload = function ()
{
try
{
const first = this.response;
resolve({ first, same: first === this.response });
}
catch (error)
{
reject(error);
}
};

xhr.onerror = function (ev)
{
reject(ev.error);
};

xhr.send(JSON.stringify({fromPM: "json"}));
})
""")
assert json_result["first"]["fromPM"] == "json"
assert json_result["same"] is True
httpd.shutdown()
asyncio.run(async_fn())
Loading