summaryrefslogtreecommitdiffstats
path: root/platform/web/js
diff options
context:
space:
mode:
authorSpartan322 <Megacake1234@gmail.com>2024-10-24 18:01:23 -0400
committerSpartan322 <Megacake1234@gmail.com>2024-10-24 18:01:23 -0400
commit3679f5971aa431d37cc2acd5d459ed4b38aad26f (patch)
treecee32a21c68b1d737fc0cbe52b2a0ff649016123 /platform/web/js
parenta22fcac9dc8ecca406a3267849954a5a5373dd11 (diff)
parent1015a481ff43edb1126ab39a147fefda290131e5 (diff)
downloadredot-engine-3679f5971aa431d37cc2acd5d459ed4b38aad26f.tar.gz
Merge commit godotengine/godot@1015a481ff43edb1126ab39a147fefda290131e5
Diffstat (limited to 'platform/web/js')
-rw-r--r--platform/web/js/libs/library_godot_fetch.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/platform/web/js/libs/library_godot_fetch.js b/platform/web/js/libs/library_godot_fetch.js
index 220f1d32cf..26f557c966 100644
--- a/platform/web/js/libs/library_godot_fetch.js
+++ b/platform/web/js/libs/library_godot_fetch.js
@@ -61,7 +61,12 @@ const GodotFetch = {
});
obj.status = response.status;
obj.response = response;
- obj.reader = response.body.getReader();
+ // `body` can be null per spec (for example, in cases where the request method is HEAD).
+ // As of the time of writing, Chromium (127.0.6533.72) does not follow the spec but Firefox (131.0.3) does.
+ // See godotengine/godot#76825 for more information.
+ // See Chromium revert (of the change to follow the spec):
+ // https://chromium.googlesource.com/chromium/src/+/135354b7bdb554cd03c913af7c90aceead03c4d4
+ obj.reader = response.body?.getReader();
obj.chunked = chunked;
},
@@ -123,6 +128,10 @@ const GodotFetch = {
}
obj.reading = true;
obj.reader.read().then(GodotFetch.onread.bind(null, id)).catch(GodotFetch.onerror.bind(null, id));
+ } else if (obj.reader == null && obj.response.body == null) {
+ // Emulate a stream closure to maintain the request lifecycle.
+ obj.reading = true;
+ GodotFetch.onread(id, { value: undefined, done: true });
}
},
},
@@ -161,7 +170,10 @@ const GodotFetch = {
if (!obj.response) {
return 0;
}
- if (obj.reader) {
+ // If the reader is nullish, but there is no body, and the request is not marked as done,
+ // the same status should be returned as though the request is currently being read
+ // so that the proper lifecycle closure can be handled in `read()`.
+ if (obj.reader || (obj.response.body == null && !obj.done)) {
return 1;
}
if (obj.done) {