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

Fix onprogress not firing when Content-Length is not available for XMLHttpRequest #44899

Closed

Conversation

BadLice
Copy link

@BadLice BadLice commented Jun 12, 2024

Summary:

When an XMLHttpRequest is performed, the onprogress event it is not invoked when the Content-Length header is missing in the response. This is the case when we are calling an endpoint that responds with transfer-encoding: chunked (https://tools.ietf.org/html/rfc9112#section-7.1), preventing the user to keep track of the progress while the server is sending chunks. Despite we will never know the total length of the content (because it will not be known due to the RFC specification, so it will be always -1), we will now be able to keep track of the loaded data.

Note that in Android, this is the current default behaviour.

To address this issue:

  • I removed the condition where the downloadProgressBlock was dispatched only when response.expectedContentLength was greater than 0
  • I created a new test case for XMLHttpRequest in the tester app to download a chunked file

Changelog:

[IOS] [CHANGED] - fire onprogress event for XMLHttpRequest even when the Content-Length header is missing in the response headers

Test Plan:

before after
https://github.com/facebook/react-native/assets/37150312/6da3518f-eed3-4808-a2f8-abe26e5c7487 https://github.com/facebook/react-native/assets/37150312/ed1da300-dcf7-4874-a941-a2289f1cb777

@facebook-github-bot
Copy link
Contributor

Hi @BadLice!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@BadLice BadLice changed the title Fix onprogress not firing when Content-Length is not available Fix onprogress not firing when Content-Length is not available for XMLHttpRequest Jun 12, 2024
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jun 12, 2024
@BadLice BadLice force-pushed the patch-download-progress-no-content-length branch from 8084223 to 5507b8b Compare June 12, 2024 13:28
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 20,364,763 +492
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 23,569,643 +112
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: b8f1b92
Branch: main

@facebook-github-bot
Copy link
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 14, 2024
@facebook-github-bot
Copy link
Contributor

@NickGerleman merged this pull request in 457d14b.

Copy link

This pull request was successfully merged by alicata in 457d14b.

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants