mirror of
https://github.com/status-im/react-native.git
synced 2025-01-16 20:44:10 +00:00
Play nice with fetch
after the newest changes that add support for XMLHttpRequest.response
Summary:After adding support for `XMLHttpRequest#response`, the `fetch` polyfill detects buffer support when debugging in Chrome and sets `responseType` to `'blob'`. In that case, the response was always empty. This change will construct a blob if `responseType` has been set to `'blob'` in order to avoid that problem Reviewed By: steveluscher Differential Revision: D3018884 fb-gh-sync-id: 4ade0413de67242c3565d95c2880d4a981ba2342 shipit-source-id: 4ade0413de67242c3565d95c2880d4a981ba2342
This commit is contained in:
parent
33e9e34648
commit
fd3a0ba781
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
var RCTNetworking = require('RCTNetworking');
|
var RCTNetworking = require('RCTNetworking');
|
||||||
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||||
|
var invariant = require('fbjs/lib/invariant');
|
||||||
|
|
||||||
const UNSENT = 0;
|
const UNSENT = 0;
|
||||||
const OPENED = 1;
|
const OPENED = 1;
|
||||||
@ -155,8 +156,16 @@ class XMLHttpRequestBase {
|
|||||||
case 'text':
|
case 'text':
|
||||||
this.response = this.responseText;
|
this.response = this.responseText;
|
||||||
break;
|
break;
|
||||||
default: //TODO: Support other types, eg: document, arraybuffer, json, blob
|
case 'blob': // whatwg-fetch sets this in Chrome
|
||||||
this.response = null;
|
/* global Blob: true */
|
||||||
|
invariant(
|
||||||
|
typeof Blob === 'function',
|
||||||
|
`responseType "blob" is only supported on platforms with native Blob support`
|
||||||
|
);
|
||||||
|
this.response = new Blob([this.responseText]);
|
||||||
|
break;
|
||||||
|
default: //TODO: Support other types, eg: document, arraybuffer, json
|
||||||
|
invariant(false, `responseType "${this.responseType}" is unsupported`);
|
||||||
}
|
}
|
||||||
this.setReadyState(this.LOADING);
|
this.setReadyState(this.LOADING);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user