-
Notifications
You must be signed in to change notification settings - Fork 25k
Description
Performing a HEAD request with fetch causes an Invalid response for blob error on iOS
Environment
Environment:
OS: macOS Sierra 10.12.6
Node: 8.6.0
Yarn: Not Found
npm: 5.3.0
Watchman: 4.9.0
Xcode: Xcode 9.1 Build version 9B55
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
react: 16.3.0-alpha.1 => 16.3.0-alpha.1
react-native: 0.54.0 => 0.54.0
Expected Behavior
The request should complete without error.
Actual Behavior
The RCTNetworking native module in iOS does not construct an empty blob for HEAD responses like Android does. Instead it returns an empty string as the response. However, whatwg-fetch always sets the responseType to blob for the XMLHttpRequest so the empty string is invalid.
Relevant lines of code:
https://github.com/github/fetch/blob/fcc4e1b48cfb5a2b1625fcd6eac06d954b00ccb6/fetch.js#L454
react-native/Libraries/Network/XMLHttpRequest.js
Lines 253 to 258 in 6eef7de
| case 'blob': | |
| if (typeof this._response === 'object' && this._response) { | |
| this._cachedResponse = BlobManager.createFromOptions(this._response); | |
| } else { | |
| throw new Error(`Invalid response for blob: ${this._response}`); | |
| } |
Invalid response for blob:
handleException @ index.bundle?platform=ios&dev=true&minify=false:13132
handleError @ index.bundle?platform=ios&dev=true&minify=false:12174
reportFatalError @ index.bundle?platform=ios&dev=true&minify=false:783
__guardSafe @ index.bundle?platform=ios&dev=true&minify=false:2360
callFunctionReturnFlushedQueue @ index.bundle?platform=ios&dev=true&minify=false:2165
t @ RNDebuggerWorker.js:1
Steps to Reproduce
1 Clone and run https://github.com/lingokids/FetchError
(I tested on an iPhone 7)