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

48 строки
1.2 KiB
JavaScript
Исходник Обычный вид История

2015-01-30 04:10:49 +03: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 04:10:49 +03:00
*
* @providesModule XMLHttpRequest
* @flow
*/
'use strict';
var RCTDataManager = require('NativeModules').DataManager;
2015-01-30 04:10:49 +03:00
var crc32 = require('crc32');
2015-03-25 05:34:12 +03:00
var XMLHttpRequestBase = require('XMLHttpRequestBase');
2015-01-30 04:10:49 +03:00
2015-03-25 05:34:12 +03:00
class XMLHttpRequest extends XMLHttpRequestBase {
2015-01-30 04:10:49 +03:00
2015-03-25 05:34:12 +03:00
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
RCTDataManager.queryData(
2015-01-30 04:10:49 +03:00
'http',
JSON.stringify({
2015-03-25 05:34:12 +03:00
method: method,
url: url,
2015-01-30 04:10:49 +03:00
data: data,
2015-03-25 05:34:12 +03:00
headers: headers,
2015-01-30 04:10:49 +03:00
}),
2015-03-25 05:34:12 +03:00
'h' + crc32(method + '|' + url + '|' + data),
2015-01-30 04:10:49 +03:00
(result) => {
result = JSON.parse(result);
2015-03-25 05:34:12 +03:00
this.callback(result.status, result.responseHeaders, result.responseText);
2015-01-30 04:10:49 +03:00
}
);
}
2015-03-25 05:34:12 +03:00
abortImpl(): void {
2015-01-30 04:10:49 +03:00
console.warn(
'XMLHttpRequest: abort() cancels JS callbacks ' +
'but not native HTTP request.'
);
}
}
module.exports = XMLHttpRequest;