Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] Always return -1 as body length in HTTPClientWeb #79846

Merged
merged 1 commit into from
Jul 24, 2023

Conversation

Faless
Copy link
Collaborator

@Faless Faless commented Jul 24, 2023

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.

See #47597 and #79327.

Reverts #77648.
Fixes #79327.

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.
@YuriSizov YuriSizov changed the title [Web] Always return -1 as body length in HTTPClientWeb. [Web] Always return -1 as body length in HTTPClientWeb Jul 24, 2023
@YuriSizov YuriSizov merged commit bec47cd into godotengine:master Jul 24, 2023
@YuriSizov
Copy link
Contributor

Thanks!

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.2.

@michaelharmonart
Copy link

michaelharmonart commented Feb 18, 2025

@Faless is this also why get_downloaded_bytes() returns 0 on the web? working without a body size is fine (I'm the one hosting the files, I can have the size of files and an md5 sum for updates etc stored in auxiliary files) but being completely unaware of any signal of how far along a download is becomes problematic

maybe I'm just missing something. is there another function I could use to get an estimate of download progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Web export HTTPRequest returns RESULT_CANT_CONNECT when API uses compression
3 participants