You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
[Web] Always return -1 as body length in HTTPClientWeb.
Body length cannot be reliably retrieved from the web. Reading the "content-length" value will return a meaningless value when the response is compressed, as reading will return uncompressed chunks in any case, resulting in a mismatch between the detected body size and the actual size returned by repeatedly calling read_response_body_chunk. Additionally, while "content-length" is considered a safe CORS header, "content-encoding" is not, so using the "content-encoding" to decide if "content-length" is meaningful is not an option either. We simply must accept the fact that browsers are awful when it comes to networking APIs.
This commit is contained in:
@@ -50,22 +50,17 @@ const GodotFetch = {
|
||||
return;
|
||||
}
|
||||
let chunked = false;
|
||||
let bodySize = -1;
|
||||
response.headers.forEach(function (value, header) {
|
||||
const v = value.toLowerCase().trim();
|
||||
const h = header.toLowerCase().trim();
|
||||
if (h === 'transfer-encoding' && v === 'chunked') {
|
||||
chunked = true;
|
||||
}
|
||||
if (h === 'content-length') {
|
||||
bodySize = parseInt(v, 10);
|
||||
}
|
||||
});
|
||||
obj.status = response.status;
|
||||
obj.response = response;
|
||||
obj.reader = response.body.getReader();
|
||||
obj.chunked = chunked;
|
||||
obj.bodySize = bodySize;
|
||||
},
|
||||
|
||||
onerror: function (id, err) {
|
||||
@@ -87,7 +82,6 @@ const GodotFetch = {
|
||||
reading: false,
|
||||
status: 0,
|
||||
chunks: [],
|
||||
bodySize: -1,
|
||||
};
|
||||
const id = IDHandler.add(obj);
|
||||
const init = {
|
||||
@@ -224,15 +218,6 @@ const GodotFetch = {
|
||||
return p_buf_size - to_read;
|
||||
},
|
||||
|
||||
godot_js_fetch_body_length_get__sig: 'ii',
|
||||
godot_js_fetch_body_length_get: function (p_id) {
|
||||
const obj = IDHandler.get(p_id);
|
||||
if (!obj || !obj.response) {
|
||||
return -1;
|
||||
}
|
||||
return obj.bodySize;
|
||||
},
|
||||
|
||||
godot_js_fetch_is_chunked__sig: 'ii',
|
||||
godot_js_fetch_is_chunked: function (p_id) {
|
||||
const obj = IDHandler.get(p_id);
|
||||
|
||||
Reference in New Issue
Block a user