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 RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
|
||||
const UNSENT = 0;
|
||||
const OPENED = 1;
|
||||
|
@ -155,8 +156,16 @@ class XMLHttpRequestBase {
|
|||
case 'text':
|
||||
this.response = this.responseText;
|
||||
break;
|
||||
default: //TODO: Support other types, eg: document, arraybuffer, json, blob
|
||||
this.response = null;
|
||||
case 'blob': // whatwg-fetch sets this in Chrome
|
||||
/* 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue