react-native-macos/Libraries/Blob
Ramanpreet Nara 9a8c06b502 Transform empty responses into empty Blobs
Summary:
In `XMLHttpRequest`, if the responseType is `Blob`, but the response is an empty string, we return `null` from `XMLHttpRequest.prototype.response()`. Instead, we should return an empty Blob. This is the behaviour on the web. To demonstrate, run the following HTTP server with Node:

## server.js
```
const http = require('http');
const server = http.createServer();

server.on('request', (request, response) => {
  if (request.url.includes('img.png')) {
    console.log('sending image');
    response.end('');
    return;
  }

  response.end('Hello World!');
});

server.listen('9000');
```

Then, open up a web browser to `http://localhost:9000`, and type the following in the console:

```
var oReq = new XMLHttpRequest();
oReq.open('GET', 'http://localhost:9000/img.png', true);
oReq.responseType = 'blob';

oReq.onload = function(oEvent) {
  var blob = oReq.response;
  console.warn(blob);
};

oReq.onerror = function(error) {
  console.warn('Error!');
};

oReq.send();
```

This warns:
```
Blob {size: 0, type: "text/xml"}
```

Changelog:
[Both][Fixed] - [RN][XMLHttpRequest] Transform empty responses into empty Blobs

Reviewed By: sahrens

Differential Revision: D19500607

fbshipit-source-id: ec35e534b32a507c8a94a29e955b7bc4c62902a0
2020-01-27 10:27:14 -08:00
..
__mocks__ Tidy up license headers [3/n] 2019-10-16 10:06:34 -07:00
__tests__ Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
Blob.js Migrate "Libraries" from Haste to standard path-based requires (sans vendor & renderers) (#24749) 2019-05-08 08:48:59 -07:00
BlobManager.js xplat/js/react-native-github 2019-08-09 10:11:15 -07:00
BlobRegistry.js Exact-by-default codemod for react-native-github 2019-11-21 09:42:57 -08:00
BlobTypes.js Exact-by-default codemod for react-native-github 2019-11-21 09:42:57 -08:00
File.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
FileReader.js Transform empty responses into empty Blobs 2020-01-27 10:27:14 -08:00
NativeBlobModule.js Fix BlobModule getConstants() 2019-12-11 11:31:51 -08:00
NativeFileReaderModule.js TM JS: Revert to import from TurboModuleRegistry.js 2019-11-08 11:44:16 -08:00
RCTBlobCollector.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTBlobCollector.mm Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTBlobManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTBlobManager.mm Fix crash in RCTBlobManager in bridgeless mode 2020-01-13 22:54:16 -08:00
RCTBlobPlugins.h Run depslint on fb_plugin_apple_library rules 2019-10-26 13:47:15 -07:00
RCTBlobPlugins.mm Make RCTFileReaderModule and RCTBlobManager TurboModule-compatible 2019-10-01 11:15:09 -07:00
RCTFileReaderModule.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTFileReaderModule.mm Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
React-RCTBlob.podspec Upgrade Folly to v2020.01.13.00 (#27810) 2020-01-21 12:44:00 -08:00
URL.js Support bare hosts. Add missing / between url (#26050) 2019-09-11 05:09:36 -07:00