Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix blob response parsing for empty body on iOS
Summary: We currently handle empty body poorly in the iOS blob implementation, this happens because of an early return that cause the blob response to not be processed by the blob module, resulting in an empty string as the body instead of a blob object. We also need to make sure to create an empty blob object when data is nil (empty body) as per the XMLHttpRequest spec. The Android implementation was already handling this properly. Fixes #18223 Send a HEAD request ```js fetch('https://apipre.monkimun.com/whoami', { body: null, method: 'HEAD', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }) ``` [IOS][BUGFIX][Blob] - Fix blob response parsing for empty body Closes #18547 Differential Revision: D7415950 Pulled By: hramos fbshipit-source-id: 56860532c6171255869f02a0960f55d155184a46
- Loading branch information
f5207ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cherry-pick into
0.54-stable
branch?f5207ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janicduplessis I've been receiving the "invalid response for Blob" error when uploading a file to a Java Spring backend using
FormData
.I copied your changes into my local Libraries and it worked pretty well. I'm no longer receiving an error, but a warning instead.
I'm now seeing this as
this._response
inXMLHttpRequest.js
For other successful requests, the size is
2
.f5207ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndrewHenderson Do you have an example request I could make to reproduce this error?
f5207ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janicduplessis Here's my request:
The endpoint was returning an empty string, which I'm assuming when it tried to parse threw the error.
Once we change the response to a timestamp, things started working properly.
Other endpoints that do not accept
multipart/form-data
work properly when returning an empty string. It's likely that my useres.json()
did it.