react-native/Libraries
Philipp von Weitershausen 08c375f828 Add responseType as a concept to RCTNetworking, send binary data as base64
Summary:
In preparation for Blob support (wherein binary XHR and WebSocket responses can be retained as native data blobs on the native side and JS receives a web-like opaque Blob object), this change makes RCTNetworking aware of the responseType that JS requests. A `xhr.responseType` of `''` or `'text'` translates to a native response type of `'text'`. A `xhr.responseType` of `arraybuffer` translates to a native response type of `base64`, as we currently lack an API to transmit TypedArrays directly to JS. This is analogous to how the WebSocket module already works, and it's a lot more versatile and much less brittle than converting a JS *string* back to a TypedArray, which is what's currently going on.

Now that we don't always send text down to JS, JS consumers might still want to get progress updates about a binary download. This is what the `'progress'` event is designed for, so this change also implements that. This change also follows the XHR spec with regards to `xhr.response` and `xhr.responseText`:

- if the response type is `'text'`, `xhr.responseText` can be peeked at by the JS consumer. It will be updated periodically as the download progresses, so long as there's either an `onreadystatechange` or `onprogress` handler on the XHR.

- if the response type is not `'text'`, `xhr.responseText` can't be accessed and `xhr.response` remains `null` until the response is fully received. `'progress'` events containing response details (total bytes, downloaded so far) are dispatched if there's an `onprogress` handler.

Once Blobs are landed, `xhr.responseType` of `'blob'` will correspond to the same native response type, which will cause RCTNetworking to only send a blob ID down to JS, which can then create a `Blob` object from that for consumers.

Closes https://github.com/facebook/react-native/pull/8324

Reviewed By: javache

Differential Revision: D3508822

Pulled By: davidaurelio

fbshipit-source-id: 441b2d4d40265b6036559c3ccb9fa962999fa5df
2016-07-13 04:58:37 -07:00
..
ART Remove `node_modules/react` from the list of discoverable haste modules 2016-07-05 06:44:33 -07:00
ActionSheetIOS Update RCTActionSheetManager.m 2016-06-04 16:28:19 -07:00
AdSupport
Animated Delete AnimatedNative-test 2016-07-11 19:43:21 -07:00
AppRegistry Remove `node_modules/react` from the list of discoverable haste modules 2016-07-05 06:44:33 -07:00
AppState iOS: Provide correct initial value for AppState.currentState 2016-07-12 23:28:22 -07:00
BatchedBridge Update some JS in preparation for some Jest updates. 2016-06-30 01:58:40 -07:00
BugReporting Unrevert D3518381 2016-07-06 12:58:41 -07:00
CameraRoll Automated changes to remove implicit capture of self in blocks: Libraries/FBReactKit/BUCK 2016-07-07 12:44:14 -07:00
Components Fixed position of ripple-effect 2016-07-08 19:33:20 -07:00
CustomComponents Fix Navigator transition. 2016-07-12 17:43:26 -07:00
DebugComponentHierarchy Move React Core Integration to a Dependency 2016-04-21 09:28:23 -07:00
Devtools Remove `node_modules/react` from the list of discoverable haste modules 2016-07-05 06:44:33 -07:00
EventEmitter Fixes EventEmitter#once arguments not getting passed to the listener 2016-06-28 16:13:21 -07:00
Experimental Wrap native module I18nManager with a new RCTI18nManager.js and fix current use of native module I18nManager 2016-07-11 20:58:32 -07:00
Fetch Better error message when trying to parse a empty body in fetch 2016-07-07 11:16:21 -07:00
Geolocation Update RCTNetworking, RCTNetInfo and RCTLocationManager to use new events system 2016-05-25 04:28:36 -07:00
Image Fix misusage of NSUInteger * in RCTImageStoreManager 2016-07-12 13:58:28 -07:00
Inspector open in editor button for yellow box 2016-07-13 04:43:25 -07:00
Interaction Fix broken link to PanResponderExample.js 2016-07-13 00:58:17 -07:00
JavaScriptAppEngine open in editor button for yellow box 2016-07-13 04:43:25 -07:00
LayoutAnimation Remove `node_modules/react` from the list of discoverable haste modules 2016-07-05 06:44:33 -07:00
Linking Hook up Android intent to Linking.js #7079 2016-06-05 18:58:24 -07:00
LinkingIOS Updated Linking and PushNotificationIOS modules to use NativeEventEmitter 2016-05-27 10:28:23 -07:00
Modal Remove `node_modules/react` from the list of discoverable haste modules 2016-07-05 06:44:33 -07:00
NativeAnimation Harmonize native animation callback args with JS 2016-07-05 11:13:23 -07:00
NavigationExperimental Prevent race condition on immediate transition 2016-07-12 13:13:24 -07:00
Network Add responseType as a concept to RCTNetworking, send binary data as base64 2016-07-13 04:58:37 -07:00
PushNotificationIOS expose remote/local flag from native side instead of JS side 2016-07-12 22:58:20 -07:00
QuickPerformanceLogger added QPL for main interactions 2015-09-29 22:25:23 -07:00
RCTTest Automated changes to remove implicit capture of self in blocks: Libraries/FBReactKit/BUCK 2016-07-07 12:44:14 -07:00
RKBackendNode Move React Core Integration to a Dependency 2016-04-21 09:28:23 -07:00
ReactIOS open in editor button for yellow box 2016-07-13 04:43:25 -07:00
ReactNative Move React Core Integration to a Dependency 2016-04-21 09:28:23 -07:00
Sample Remove knowledge of fbjs from the packager 2016-03-02 04:28:38 -08:00
Settings Automated changes to remove implicit capture of self in blocks: Libraries/FBReactKit/BUCK 2016-07-07 12:44:14 -07:00
Storage Update AsyncStorage doc 2016-06-24 08:43:36 -07:00
StyleSheet Unrevert D3518381 2016-07-06 12:58:41 -07:00
Text Implement TextInput onContentSizeChange 2016-07-07 09:00:01 -07:00
Utilities Wrap native module I18nManager with a new RCTI18nManager.js and fix current use of native module I18nManager 2016-07-11 20:58:32 -07:00
Vibration Add support for vibration patterns 2016-03-29 21:45:20 -07:00
WebSocket Automated changes to remove implicit capture of self in blocks: Libraries/FBReactKit/BUCK 2016-07-07 12:44:14 -07:00
react-native Fix Relay tests, fix React.js whitespace 2016-07-12 21:43:23 -07:00
vendor Fixed NativeEventListener deregistration 2016-05-16 04:13:56 -07:00
Promise.js Remove knowledge of fbjs from the packager 2016-03-02 04:28:38 -08:00
promiseRejectionIsError.js Add possibility to `console.error`/redbox on promise rejections 2016-03-15 05:22:22 -07:00