Bring back trackingName
Reviewed By: yungsters Differential Revision: D3501805 fbshipit-source-id: be7e1a76c022d050542af797dda49b3cf14340bb
This commit is contained in:
parent
9b184cc0f4
commit
4d6c1e55d7
|
@ -27,7 +27,7 @@ function convertHeadersMapToArray(headers: Object): Array<Header> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let _requestId = 1;
|
let _requestId = 1;
|
||||||
function generateRequestId() {
|
function generateRequestId(): number {
|
||||||
return _requestId++;
|
return _requestId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,16 @@ class RCTNetworking extends NativeEventEmitter {
|
||||||
super(RCTNetworkingNative);
|
super(RCTNetworkingNative);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendRequest(method, url, headers, data, incrementalUpdates, timeout, callback) {
|
sendRequest(
|
||||||
|
method: ?string,
|
||||||
|
trackingName: string,
|
||||||
|
url: ?string,
|
||||||
|
headers: Object,
|
||||||
|
data: string | FormData | Object,
|
||||||
|
incrementalUpdates: boolean,
|
||||||
|
timeout: number,
|
||||||
|
callback: (requestId: number) => void,
|
||||||
|
) {
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
data = {string: data};
|
data = {string: data};
|
||||||
} else if (data instanceof FormData) {
|
} else if (data instanceof FormData) {
|
||||||
|
@ -52,6 +61,7 @@ class RCTNetworking extends NativeEventEmitter {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
data = {...data, trackingName};
|
||||||
const requestId = generateRequestId();
|
const requestId = generateRequestId();
|
||||||
RCTNetworkingNative.sendRequest(
|
RCTNetworkingNative.sendRequest(
|
||||||
method,
|
method,
|
||||||
|
@ -65,11 +75,11 @@ class RCTNetworking extends NativeEventEmitter {
|
||||||
callback(requestId);
|
callback(requestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
abortRequest(requestId) {
|
abortRequest(requestId: number) {
|
||||||
RCTNetworkingNative.abortRequest(requestId);
|
RCTNetworkingNative.abortRequest(requestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCookies(callback) {
|
clearCookies(callback: number) {
|
||||||
RCTNetworkingNative.clearCookies(callback);
|
RCTNetworkingNative.clearCookies(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,22 @@ class RCTNetworking extends NativeEventEmitter {
|
||||||
super(RCTNetworkingNative);
|
super(RCTNetworkingNative);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendRequest(method, url, headers, data, incrementalUpdates, timeout, callback) {
|
sendRequest(
|
||||||
|
method: ?string,
|
||||||
|
trackingName: string,
|
||||||
|
url: ?string,
|
||||||
|
headers: Object,
|
||||||
|
data: string | FormData | Object,
|
||||||
|
incrementalUpdates: boolean,
|
||||||
|
timeout: number,
|
||||||
|
callback: (requestId: number) => void,
|
||||||
|
) {
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
data = {string: data};
|
data = {string: data};
|
||||||
} else if (data instanceof FormData) {
|
} else if (data instanceof FormData) {
|
||||||
data = {formData: data.getParts()};
|
data = {formData: data.getParts()};
|
||||||
}
|
}
|
||||||
|
data = {...data, trackingName};
|
||||||
RCTNetworkingNative.sendRequest({
|
RCTNetworkingNative.sendRequest({
|
||||||
method,
|
method,
|
||||||
url,
|
url,
|
||||||
|
@ -36,11 +46,11 @@ class RCTNetworking extends NativeEventEmitter {
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
abortRequest(requestId) {
|
abortRequest(requestId: number) {
|
||||||
RCTNetworkingNative.abortRequest(requestId);
|
RCTNetworkingNative.abortRequest(requestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCookies(callback) {
|
clearCookies(callback: number) {
|
||||||
console.warn('RCTNetworking.clearCookies is not supported on iOS');
|
console.warn('RCTNetworking.clearCookies is not supported on iOS');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
|
||||||
_sent: boolean;
|
_sent: boolean;
|
||||||
_url: ?string = null;
|
_url: ?string = null;
|
||||||
_timedOut: boolean = false;
|
_timedOut: boolean = false;
|
||||||
|
_trackingName: string = 'unknown';
|
||||||
_incrementalEvents: boolean = false;
|
_incrementalEvents: boolean = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -322,6 +323,14 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
|
||||||
this._headers[header.toLowerCase()] = value;
|
this._headers[header.toLowerCase()] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom extension for tracking origins of request.
|
||||||
|
*/
|
||||||
|
setTrackingName(trackingName: string): XMLHttpRequest {
|
||||||
|
this._trackingName = trackingName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
open(method: string, url: string, async: ?boolean): void {
|
open(method: string, url: string, async: ?boolean): void {
|
||||||
/* Other optional arguments are not supported yet */
|
/* Other optional arguments are not supported yet */
|
||||||
if (this.readyState !== this.UNSENT) {
|
if (this.readyState !== this.UNSENT) {
|
||||||
|
@ -367,6 +376,7 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
|
||||||
));
|
));
|
||||||
RCTNetworking.sendRequest(
|
RCTNetworking.sendRequest(
|
||||||
method,
|
method,
|
||||||
|
this._trackingName,
|
||||||
url,
|
url,
|
||||||
headers,
|
headers,
|
||||||
data,
|
data,
|
||||||
|
|
Loading…
Reference in New Issue