From fd3a0ba781082a567d5713524fb269877baa0b1d Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Mon, 7 Mar 2016 13:28:46 -0800 Subject: [PATCH] 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 --- Libraries/Network/XMLHttpRequestBase.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Libraries/Network/XMLHttpRequestBase.js b/Libraries/Network/XMLHttpRequestBase.js index da96cc13f..e82ce515a 100644 --- a/Libraries/Network/XMLHttpRequestBase.js +++ b/Libraries/Network/XMLHttpRequestBase.js @@ -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); }