react-native/Libraries/Network/XMLHttpRequest.ios.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-01-30 01:10:49 +00: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-30 01:10:49 +00:00
*
* @providesModule XMLHttpRequest
* @flow
*/
'use strict';
var FormData = require('FormData');
var RCTNetworking = require('RCTNetworking');
2015-01-30 01:10:49 +00:00
2015-03-25 02:34:12 +00:00
var XMLHttpRequestBase = require('XMLHttpRequestBase');
2015-01-30 01:10:49 +00:00
2015-03-25 02:34:12 +00:00
class XMLHttpRequest extends XMLHttpRequestBase {
constructor() {
super();
// iOS supports upload
this.upload = {};
}
2015-03-25 02:34:12 +00:00
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
if (typeof data === 'string') {
data = {string: data};
2015-08-14 12:13:40 +00:00
} else if (data instanceof FormData) {
data = {formData: data.getParts()};
}
RCTNetworking.sendRequest(
{
method,
url,
data,
headers,
incrementalUpdates: this.onreadystatechange ? true : false,
},
this.didCreateRequest.bind(this)
2015-01-30 01:10:49 +00:00
);
}
}
module.exports = XMLHttpRequest;