-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Expand file tree
/
Copy pathXMLHttpRequest.android.js
More file actions
66 lines (56 loc) · 1.55 KB
/
Copy pathXMLHttpRequest.android.js
File metadata and controls
66 lines (56 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* 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.
*
* @providesModule XMLHttpRequest
* @flow
*/
'use strict';
var FormData = require('FormData');
var RCTNetworking = require('RCTNetworking');
var XMLHttpRequestBase = require('XMLHttpRequestBase');
type Header = [string, string];
function convertHeadersMapToArray(headers: Object): Array<Header> {
var headerArray = [];
for (var name in headers) {
headerArray.push([name, headers[name]]);
}
return headerArray;
}
class XMLHttpRequest extends XMLHttpRequestBase {
_requestId: ?number;
constructor() {
super();
this._requestId = null;
}
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
var body;
if (typeof data === 'string') {
body = {string: data};
} else if (data instanceof FormData) {
body = {
formData: data.getParts().map((part) => {
part.headers = convertHeadersMapToArray(part.headers);
return part;
}),
};
} else {
body = data;
}
this._requestId = RCTNetworking.sendRequest(
method,
url,
convertHeadersMapToArray(headers),
body,
this.callback.bind(this)
);
}
abortImpl(): void {
this._requestId && RCTNetworking.abortRequest(this._requestId);
}
}
module.exports = XMLHttpRequest;