2015-01-29 17:10:49 -08:00
|
|
|
/**
|
2015-03-23 15:07:33 -07:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-01-29 17:10:49 -08:00
|
|
|
*
|
|
|
|
* @providesModule XMLHttpRequest
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-06-09 12:25:24 -07:00
|
|
|
var FormData = require('FormData');
|
2015-11-17 06:28:44 -08:00
|
|
|
var RCTNetworking = require('RCTNetworking');
|
2015-01-29 17:10:49 -08:00
|
|
|
|
2015-03-24 19:34:12 -07:00
|
|
|
var XMLHttpRequestBase = require('XMLHttpRequestBase');
|
2015-01-29 17:10:49 -08:00
|
|
|
|
2015-03-24 19:34:12 -07:00
|
|
|
class XMLHttpRequest extends XMLHttpRequestBase {
|
2015-06-05 15:23:30 -07:00
|
|
|
constructor() {
|
|
|
|
super();
|
2015-11-17 06:28:44 -08:00
|
|
|
// iOS supports upload
|
2015-07-20 22:44:51 -07:00
|
|
|
this.upload = {};
|
2015-06-05 15:23:30 -07:00
|
|
|
}
|
|
|
|
|
2015-03-24 19:34:12 -07:00
|
|
|
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
|
2015-06-09 12:25:24 -07:00
|
|
|
if (typeof data === 'string') {
|
2015-07-31 18:54:25 -07:00
|
|
|
data = {string: data};
|
2015-08-14 05:13:40 -07:00
|
|
|
} else if (data instanceof FormData) {
|
2015-07-31 18:54:25 -07:00
|
|
|
data = {formData: data.getParts()};
|
2015-06-09 12:25:24 -07:00
|
|
|
}
|
2015-06-18 09:41:38 -07:00
|
|
|
RCTNetworking.sendRequest(
|
2015-04-10 01:33:10 -07:00
|
|
|
{
|
2015-06-09 12:25:24 -07:00
|
|
|
method,
|
|
|
|
url,
|
2015-07-31 18:54:25 -07:00
|
|
|
data,
|
2015-06-09 12:25:24 -07:00
|
|
|
headers,
|
2015-06-09 12:25:33 -07:00
|
|
|
incrementalUpdates: this.onreadystatechange ? true : false,
|
2015-04-10 01:33:10 -07:00
|
|
|
},
|
2015-11-17 06:28:44 -08:00
|
|
|
this.didCreateRequest.bind(this)
|
2015-01-29 17:10:49 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = XMLHttpRequest;
|