@microsoft/1ds-post-js 3.1.10 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -6
- package/bundle/{ms.post-3.1.10.gbl.js → ms.post-3.2.1.gbl.js} +1502 -725
- package/bundle/ms.post-3.2.1.gbl.js.map +1 -0
- package/bundle/ms.post-3.2.1.gbl.min.js +7 -0
- package/bundle/ms.post-3.2.1.gbl.min.js.map +1 -0
- package/bundle/ms.post-3.2.1.integrity.json +46 -0
- package/bundle/{ms.post-3.1.10.js → ms.post-3.2.1.js} +1502 -725
- package/bundle/ms.post-3.2.1.js.map +1 -0
- package/bundle/ms.post-3.2.1.min.js +7 -0
- package/bundle/ms.post-3.2.1.min.js.map +1 -0
- package/bundle/ms.post.gbl.js +1501 -724
- package/bundle/ms.post.gbl.js.map +1 -1
- package/bundle/ms.post.gbl.min.js +2 -2
- package/bundle/ms.post.gbl.min.js.map +1 -1
- package/bundle/ms.post.integrity.json +17 -17
- package/bundle/ms.post.js +1501 -724
- package/bundle/ms.post.js.map +1 -1
- package/bundle/ms.post.min.js +2 -2
- package/bundle/ms.post.min.js.map +1 -1
- package/dist/ms.post.js +264 -149
- package/dist/ms.post.js.map +1 -1
- package/dist/ms.post.min.js +2 -2
- package/dist/ms.post.min.js.map +1 -1
- package/dist-esm/src/BatchNotificationActions.js +1 -1
- package/dist-esm/src/ClockSkewManager.js +1 -1
- package/dist-esm/src/Constants.d.ts +1 -0
- package/dist-esm/src/Constants.js +2 -1
- package/dist-esm/src/Constants.js.map +1 -1
- package/dist-esm/src/DataModels.d.ts +49 -0
- package/dist-esm/src/DataModels.js +1 -1
- package/dist-esm/src/EventBatch.js +1 -1
- package/dist-esm/src/HttpManager.d.ts +1 -1
- package/dist-esm/src/HttpManager.js +102 -58
- package/dist-esm/src/HttpManager.js.map +1 -1
- package/dist-esm/src/Index.js +1 -1
- package/dist-esm/src/KillSwitch.js +1 -1
- package/dist-esm/src/PostChannel.d.ts +0 -4
- package/dist-esm/src/PostChannel.js +171 -104
- package/dist-esm/src/PostChannel.js.map +1 -1
- package/dist-esm/src/RetryPolicy.d.ts +20 -25
- package/dist-esm/src/RetryPolicy.js +35 -44
- package/dist-esm/src/RetryPolicy.js.map +1 -1
- package/dist-esm/src/Serializer.js +1 -1
- package/dist-esm/src/typings/XDomainRequest.js +1 -1
- package/package.json +2 -2
- package/src/Constants.ts +1 -0
- package/src/DataModels.ts +62 -1
- package/src/HttpManager.ts +110 -69
- package/src/PostChannel.ts +203 -127
- package/src/RetryPolicy.ts +33 -38
- package/bundle/ms.post-3.1.10.gbl.js.map +0 -1
- package/bundle/ms.post-3.1.10.gbl.min.js +0 -7
- package/bundle/ms.post-3.1.10.gbl.min.js.map +0 -1
- package/bundle/ms.post-3.1.10.integrity.json +0 -46
- package/bundle/ms.post-3.1.10.js.map +0 -1
- package/bundle/ms.post-3.1.10.min.js +0 -7
- package/bundle/ms.post-3.1.10.min.js.map +0 -1
package/src/HttpManager.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
import {
|
|
7
7
|
isReactNative, isValueAssigned, isString, getTime, arrForEach, getLocation, strTrim, isFetchSupported, isXhrSupported,
|
|
8
8
|
isBeaconsSupported, FullVersionString, useXDomainRequest, IExtendedAppInsightsCore, IExtendedConfiguration,
|
|
9
|
-
|
|
9
|
+
eLoggingSeverity, _eExtendedInternalMessageId, SendRequestReason, strUndefined, getNavigator, doPerf, IPerfEvent,
|
|
10
10
|
dateNow, isUndefined, isNullOrUndefined, objForEachKey, ICookieMgr, isNumber, isArray, TransportType, dumpObj, objKeys, extend,
|
|
11
|
-
EventSendType, hasOwnProperty, openXhr
|
|
11
|
+
EventSendType, hasOwnProperty, openXhr, _throwInternal, _eInternalMessageId
|
|
12
12
|
} from "@microsoft/1ds-core-js";
|
|
13
13
|
import {
|
|
14
14
|
IXHROverride, IPostTransmissionTelemetryItem, ICollectorResult,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
import { BatchNotificationAction, BatchNotificationActions } from "./BatchNotificationActions";
|
|
19
19
|
import { EventBatch } from "./EventBatch";
|
|
20
20
|
import { Serializer, ISerializedPayload } from "./Serializer";
|
|
21
|
-
import
|
|
21
|
+
import { retryPolicyGetMillisToBackoffForRetry, retryPolicyShouldRetryForStatus } from "./RetryPolicy";
|
|
22
22
|
import EVTKillSwitch from "./KillSwitch";
|
|
23
23
|
import EVTClockSkewManager from "./ClockSkewManager";
|
|
24
24
|
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
@@ -27,10 +27,14 @@ import { XDomainRequest as IXDomainRequest } from "./typings/XDomainRequest";
|
|
|
27
27
|
import {
|
|
28
28
|
defaultCacheControl, defaultContentType, DisabledPropertyName, Method, strApiKey, strAuthXToken, strCacheControl,
|
|
29
29
|
strClientId, strClientVersion, strContentTypeHeader, strDropped, strKillDurationHeader, strKillDurationSecondsHeader,
|
|
30
|
-
strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader,
|
|
30
|
+
strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strNoResponseBody, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader,
|
|
31
31
|
strTimeDeltaToApply, strUploadTime
|
|
32
32
|
} from "./Constants";
|
|
33
33
|
|
|
34
|
+
const strSendAttempt = "sendAttempt";
|
|
35
|
+
|
|
36
|
+
const _noResponseQs = "&" + strNoResponseBody + "=true";
|
|
37
|
+
|
|
34
38
|
// TypeScript removed this interface so we need to declare the global so we can check for it's existence.
|
|
35
39
|
declare var XDomainRequest: {
|
|
36
40
|
prototype: IXDomainRequest;
|
|
@@ -57,23 +61,20 @@ const _eventActionMap: any = {
|
|
|
57
61
|
const _collectorQsHeaders = { };
|
|
58
62
|
const _collectorHeaderToQs = { };
|
|
59
63
|
|
|
60
|
-
function _addCollectorHeaderQsMapping(qsName: string, headerName: string) {
|
|
64
|
+
function _addCollectorHeaderQsMapping(qsName: string, headerName: string, allowQs?: boolean) {
|
|
61
65
|
_collectorQsHeaders[qsName] = headerName;
|
|
62
|
-
|
|
66
|
+
if (allowQs !== false) {
|
|
67
|
+
_collectorHeaderToQs[headerName] = qsName;
|
|
68
|
+
}
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
_addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
//_addCollectorHeaderQsMapping(strApiKey, strApiKey);
|
|
73
|
-
//_addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);
|
|
74
|
-
//_addCollectorHeaderQsMapping(strUploadTime, strUploadTime);
|
|
75
|
-
//_addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);
|
|
76
|
-
// ----------------------------------------------------------------------------------------------------------------
|
|
71
|
+
_addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket, false);
|
|
72
|
+
_addCollectorHeaderQsMapping(strClientVersion, strClientVersion);
|
|
73
|
+
_addCollectorHeaderQsMapping(strClientId, "Client-Id");
|
|
74
|
+
_addCollectorHeaderQsMapping(strApiKey, strApiKey);
|
|
75
|
+
_addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);
|
|
76
|
+
_addCollectorHeaderQsMapping(strUploadTime, strUploadTime);
|
|
77
|
+
_addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);
|
|
77
78
|
|
|
78
79
|
type OnCompleteCallback = (status: number, headers: { [headerName: string]: string }, response?: string) => void;
|
|
79
80
|
|
|
@@ -140,7 +141,7 @@ export class HttpManager {
|
|
|
140
141
|
* @constructor
|
|
141
142
|
* @param requestQueue - The queue that contains the requests to be sent.
|
|
142
143
|
*/
|
|
143
|
-
constructor(maxEventsPerBatch: number, maxConnections: number,
|
|
144
|
+
constructor(maxEventsPerBatch: number, maxConnections: number, maxRequestRetriesBeforeBackoff: number, actions: BatchNotificationActions) {
|
|
144
145
|
let _urlString: string = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
|
|
145
146
|
let _killSwitch: EVTKillSwitch = new EVTKillSwitch();
|
|
146
147
|
let _paused = false;
|
|
@@ -159,6 +160,8 @@ export class HttpManager {
|
|
|
159
160
|
let _cookieMgr: ICookieMgr;
|
|
160
161
|
let _isUnloading = false;
|
|
161
162
|
let _useHeaders = false;
|
|
163
|
+
let _xhrTimeout: number;
|
|
164
|
+
let _disableXhrSync: boolean;
|
|
162
165
|
|
|
163
166
|
dynamicProto(HttpManager, this, (_self) => {
|
|
164
167
|
let _sendCredentials = true;
|
|
@@ -176,8 +179,7 @@ export class HttpManager {
|
|
|
176
179
|
|
|
177
180
|
_urlString = endpointUrl + _urlString;
|
|
178
181
|
|
|
179
|
-
|
|
180
|
-
_useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;
|
|
182
|
+
_useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
|
|
181
183
|
_core = core;
|
|
182
184
|
_cookieMgr = core.getCookieMgr();
|
|
183
185
|
_enableEventTimings = !(_core.config as IExtendedConfiguration).disableEventTimings;
|
|
@@ -189,10 +191,15 @@ export class HttpManager {
|
|
|
189
191
|
enableCompoundKey = !!channelConfig.enableCompoundKey;
|
|
190
192
|
}
|
|
191
193
|
|
|
194
|
+
_xhrTimeout = channelConfig.xhrTimeout;
|
|
195
|
+
_disableXhrSync = channelConfig.disableXhrSync;
|
|
196
|
+
|
|
192
197
|
_useBeacons = !isReactNative(); // Only use beacons if not running in React Native
|
|
193
198
|
_serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
|
|
194
199
|
|
|
195
200
|
let syncHttpInterface = httpInterface;
|
|
201
|
+
let beaconHttpInterface: IXHROverride = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
|
|
202
|
+
let fetchSyncHttpInterface: IXHROverride = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
|
|
196
203
|
|
|
197
204
|
if (!httpInterface) {
|
|
198
205
|
_customHttpInterface = false;
|
|
@@ -232,8 +239,8 @@ export class HttpManager {
|
|
|
232
239
|
_sendInterfaces = {
|
|
233
240
|
[EventSendType.Batched]: httpInterface,
|
|
234
241
|
[EventSendType.Synchronous]: syncHttpInterface || _getSenderInterface([TransportType.Xhr, TransportType.Fetch, TransportType.Beacon], true),
|
|
235
|
-
[EventSendType.SendBeacon]: _getSenderInterface([TransportType.Beacon, TransportType.Fetch, TransportType.Xhr], true)
|
|
236
|
-
[EventSendType.SyncFetch]: _getSenderInterface([TransportType.Fetch, TransportType.Beacon, TransportType.Xhr], true)
|
|
242
|
+
[EventSendType.SendBeacon]: beaconHttpInterface || _getSenderInterface([TransportType.Beacon, TransportType.Fetch], true) || syncHttpInterface || _getSenderInterface([TransportType.Xhr], true),
|
|
243
|
+
[EventSendType.SyncFetch]: fetchSyncHttpInterface || _getSenderInterface([TransportType.Fetch, TransportType.Beacon], true) || syncHttpInterface || _getSenderInterface([TransportType.Xhr], true)
|
|
237
244
|
};
|
|
238
245
|
};
|
|
239
246
|
|
|
@@ -278,6 +285,9 @@ export class HttpManager {
|
|
|
278
285
|
// It doesn't support custom headers, so no action is taken with current requestHeaders
|
|
279
286
|
let xdr = new XDomainRequest();
|
|
280
287
|
xdr.open(Method, payload.urlString);
|
|
288
|
+
if (payload.timeout) {
|
|
289
|
+
xdr.timeout = payload.timeout;
|
|
290
|
+
}
|
|
281
291
|
|
|
282
292
|
// can't get the status code in xdr.
|
|
283
293
|
xdr.onload = () => {
|
|
@@ -310,6 +320,7 @@ export class HttpManager {
|
|
|
310
320
|
}
|
|
311
321
|
|
|
312
322
|
function _fetchSendPost(payload: IPayloadData, oncomplete: OnCompleteCallback, sync?: boolean) {
|
|
323
|
+
let theUrl = payload.urlString;
|
|
313
324
|
let ignoreResponse = false;
|
|
314
325
|
let responseHandled = false;
|
|
315
326
|
let requestInit: RequestInit = {
|
|
@@ -324,6 +335,7 @@ export class HttpManager {
|
|
|
324
335
|
// As a sync request (during unload), it is unlikely that we will get a chance to process the response so
|
|
325
336
|
// just like beacon send assume that the events have been accepted and processed
|
|
326
337
|
ignoreResponse = true;
|
|
338
|
+
theUrl += _noResponseQs;
|
|
327
339
|
}
|
|
328
340
|
}
|
|
329
341
|
|
|
@@ -337,7 +349,7 @@ export class HttpManager {
|
|
|
337
349
|
requestInit.headers = payload.headers;
|
|
338
350
|
}
|
|
339
351
|
|
|
340
|
-
fetch(
|
|
352
|
+
fetch(theUrl, requestInit).then((response) => {
|
|
341
353
|
let headerMap = {};
|
|
342
354
|
let responseText = "";
|
|
343
355
|
if (response.headers) {
|
|
@@ -370,9 +382,21 @@ export class HttpManager {
|
|
|
370
382
|
responseHandled = true;
|
|
371
383
|
_doOnComplete(oncomplete, 200, {});
|
|
372
384
|
}
|
|
385
|
+
|
|
386
|
+
if (!responseHandled && payload.timeout > 0) {
|
|
387
|
+
// Simulate timeout
|
|
388
|
+
_postManager._setTimeoutOverride(() => {
|
|
389
|
+
if (!responseHandled) {
|
|
390
|
+
// Assume a 500 response (which will cause a retry)
|
|
391
|
+
responseHandled = true;
|
|
392
|
+
_doOnComplete(oncomplete, 500, {});
|
|
393
|
+
}
|
|
394
|
+
}, payload.timeout);
|
|
395
|
+
}
|
|
373
396
|
}
|
|
374
397
|
|
|
375
398
|
function _xhrSendPost(payload: IPayloadData, oncomplete: OnCompleteCallback, sync?: boolean) {
|
|
399
|
+
let theUrl = payload.urlString;
|
|
376
400
|
|
|
377
401
|
function _appendHeader(theHeaders, xhr, name) {
|
|
378
402
|
if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
|
|
@@ -405,33 +429,37 @@ export class HttpManager {
|
|
|
405
429
|
function xhrComplete(xhr, responseTxt?) {
|
|
406
430
|
_doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
|
|
407
431
|
}
|
|
432
|
+
if (sync && payload.disableXhrSync) {
|
|
433
|
+
sync = false;
|
|
434
|
+
}
|
|
408
435
|
|
|
409
|
-
let
|
|
436
|
+
let xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);
|
|
410
437
|
|
|
411
438
|
// Set custom headers (e.g. gzip) here (after open())
|
|
412
439
|
objForEachKey(payload.headers, (name, value) => {
|
|
413
|
-
|
|
440
|
+
xhrRequest.setRequestHeader(name, value);
|
|
414
441
|
});
|
|
415
|
-
|
|
416
|
-
let response = _getResponseText(
|
|
417
|
-
xhrComplete(
|
|
442
|
+
xhrRequest.onload = () => {
|
|
443
|
+
let response = _getResponseText(xhrRequest);
|
|
444
|
+
xhrComplete(xhrRequest, response);
|
|
418
445
|
_handleCollectorResponse(response);
|
|
419
446
|
};
|
|
420
|
-
|
|
421
|
-
xhrComplete(
|
|
447
|
+
xhrRequest.onerror = () => {
|
|
448
|
+
xhrComplete(xhrRequest);
|
|
422
449
|
};
|
|
423
|
-
|
|
424
|
-
xhrComplete(
|
|
450
|
+
xhrRequest.ontimeout = () => {
|
|
451
|
+
xhrComplete(xhrRequest);
|
|
425
452
|
};
|
|
426
|
-
|
|
453
|
+
xhrRequest.send(payload.data);
|
|
427
454
|
}
|
|
428
455
|
|
|
429
456
|
function _doOnComplete(oncomplete: OnCompleteCallback, status: number, headers: { [headerName: string]: string }, response?: string) {
|
|
430
457
|
try {
|
|
431
458
|
oncomplete(status, headers, response);
|
|
432
459
|
} catch (e) {
|
|
433
|
-
_postManager.diagLog()
|
|
434
|
-
|
|
460
|
+
_throwInternal(_postManager.diagLog(),
|
|
461
|
+
eLoggingSeverity.WARNING,
|
|
462
|
+
_eExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));
|
|
435
463
|
}
|
|
436
464
|
}
|
|
437
465
|
|
|
@@ -440,9 +468,11 @@ export class HttpManager {
|
|
|
440
468
|
let internalPayloadData = payload as IInternalPayloadData;
|
|
441
469
|
let status = 200;
|
|
442
470
|
let thePayload = internalPayloadData._thePayload;
|
|
471
|
+
let theUrl = payload.urlString + _noResponseQs;
|
|
472
|
+
|
|
443
473
|
try {
|
|
444
474
|
let nav = getNavigator();
|
|
445
|
-
if (!nav.sendBeacon(
|
|
475
|
+
if (!nav.sendBeacon(theUrl, payload.data)) {
|
|
446
476
|
if (thePayload) {
|
|
447
477
|
// Failed to send entire payload so try and split data and try to send as much events as possible
|
|
448
478
|
let droppedBatches: EventBatch[] = [];
|
|
@@ -450,7 +480,7 @@ export class HttpManager {
|
|
|
450
480
|
if (droppedBatches && theBatch && theBatch.count() > 0) {
|
|
451
481
|
let theEvents = theBatch.events();
|
|
452
482
|
for (let lp = 0; lp < theEvents.length; lp++) {
|
|
453
|
-
if (!nav.sendBeacon(
|
|
483
|
+
if (!nav.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
|
|
454
484
|
// Can't send anymore, so split the batch and drop the rest
|
|
455
485
|
droppedBatches.push(theBatch.split(lp));
|
|
456
486
|
break;
|
|
@@ -469,7 +499,7 @@ export class HttpManager {
|
|
|
469
499
|
}
|
|
470
500
|
|
|
471
501
|
} catch (ex) {
|
|
472
|
-
_postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + ex);
|
|
502
|
+
_postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
|
|
473
503
|
status = 0;
|
|
474
504
|
} finally {
|
|
475
505
|
_doOnComplete(oncomplete, status, {}, "");
|
|
@@ -707,8 +737,9 @@ export class HttpManager {
|
|
|
707
737
|
_sendBatchesNotification(droppedBatches, EventBatchNotificationReason.KillSwitch, sendType);
|
|
708
738
|
}, () => ({ batches: _createDebugBatches(orgBatches), retryCount, isTeardown, isSynchronous, sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType }), !isSynchronous);
|
|
709
739
|
} catch (ex) {
|
|
710
|
-
_postManager.diagLog()
|
|
711
|
-
|
|
740
|
+
_throwInternal(_postManager.diagLog(),
|
|
741
|
+
eLoggingSeverity.WARNING,
|
|
742
|
+
_eInternalMessageId.CannotSerializeObject, "Unexpected Exception sending batch: " + dumpObj(ex));
|
|
712
743
|
}
|
|
713
744
|
}
|
|
714
745
|
|
|
@@ -719,26 +750,22 @@ export class HttpManager {
|
|
|
719
750
|
useHdrs: false // Assume no headers
|
|
720
751
|
};
|
|
721
752
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
// }
|
|
735
|
-
// });
|
|
736
|
-
// } else {
|
|
753
|
+
if (!useHeaders) {
|
|
754
|
+
// Attempt to map headers to a query string if possible
|
|
755
|
+
objForEachKey(_headers, (name, value) => {
|
|
756
|
+
if (_collectorHeaderToQs[name]) {
|
|
757
|
+
_addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
|
|
758
|
+
} else {
|
|
759
|
+
// No mapping, so just include in the headers anyway (may not get sent if using sendBeacon())
|
|
760
|
+
requestDetails.hdrs[name] = value;
|
|
761
|
+
requestDetails.useHdrs = true;
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
} else {
|
|
737
765
|
// Copy the pre-defined headers into the payload headers
|
|
738
766
|
requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
|
|
739
767
|
requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
|
|
740
|
-
|
|
741
|
-
// ----------------------------------------------------------------------------------------------------------------
|
|
768
|
+
}
|
|
742
769
|
|
|
743
770
|
_addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
|
|
744
771
|
_addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
|
|
@@ -809,7 +836,6 @@ export class HttpManager {
|
|
|
809
836
|
useHeaders = useHeaders || requestDetails.useHdrs;
|
|
810
837
|
|
|
811
838
|
let sendEventStart = getTime();
|
|
812
|
-
let strSendAttempt = "sendAttempt";
|
|
813
839
|
|
|
814
840
|
doPerf(_core, () => "HttpManager:_doPayloadSend", () => {
|
|
815
841
|
// Increment the send attempt count and add timings after packaging (So it's not serialized in the 1st attempt)
|
|
@@ -844,9 +870,14 @@ export class HttpManager {
|
|
|
844
870
|
urlString: requestDetails.url,
|
|
845
871
|
headers: requestDetails.hdrs,
|
|
846
872
|
_thePayload: thePayload,
|
|
847
|
-
_sendReason: sendReason
|
|
873
|
+
_sendReason: sendReason,
|
|
874
|
+
timeout: _xhrTimeout
|
|
848
875
|
};
|
|
849
876
|
|
|
877
|
+
if (!isUndefined(_disableXhrSync)) {
|
|
878
|
+
orgPayloadData.disableXhrSync = !!_disableXhrSync;
|
|
879
|
+
}
|
|
880
|
+
|
|
850
881
|
// Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call
|
|
851
882
|
if (useHeaders) {
|
|
852
883
|
if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
|
|
@@ -902,7 +933,9 @@ export class HttpManager {
|
|
|
902
933
|
let hookData: IPayloadData = {
|
|
903
934
|
data: orgPayloadData.data,
|
|
904
935
|
urlString: orgPayloadData.urlString,
|
|
905
|
-
headers: extend({}, orgPayloadData.headers)
|
|
936
|
+
headers: extend({}, orgPayloadData.headers),
|
|
937
|
+
timeout: orgPayloadData.timeout,
|
|
938
|
+
disableXhrSync: orgPayloadData.disableXhrSync
|
|
906
939
|
};
|
|
907
940
|
|
|
908
941
|
let senderCalled = false;
|
|
@@ -988,13 +1021,13 @@ export class HttpManager {
|
|
|
988
1021
|
|
|
989
1022
|
// Disabling triple-equals rule to avoid httpOverrides from failing because they are returning a string value
|
|
990
1023
|
// tslint:disable-next-line:triple-equals
|
|
991
|
-
if (status == 200) {
|
|
1024
|
+
if (status == 200 || status == 204) {
|
|
992
1025
|
// Response was successfully sent
|
|
993
1026
|
reason = EventBatchNotificationReason.Complete;
|
|
994
1027
|
return;
|
|
995
1028
|
}
|
|
996
1029
|
|
|
997
|
-
if (!
|
|
1030
|
+
if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
|
|
998
1031
|
// Only retry for specific response codes and if there is still events after kill switch processing
|
|
999
1032
|
shouldRetry = false;
|
|
1000
1033
|
}
|
|
@@ -1008,7 +1041,8 @@ export class HttpManager {
|
|
|
1008
1041
|
reason = EventBatchNotificationReason.RequeueEvents;
|
|
1009
1042
|
let retryCount = thePayload.retryCnt;
|
|
1010
1043
|
if (thePayload.sendType === EventSendType.Batched) {
|
|
1011
|
-
|
|
1044
|
+
// attempt to resend the entire batch
|
|
1045
|
+
if (retryCount < maxRequestRetriesBeforeBackoff) {
|
|
1012
1046
|
isRetrying = true;
|
|
1013
1047
|
_doAction(() => {
|
|
1014
1048
|
// try to resend the same batches
|
|
@@ -1020,9 +1054,14 @@ export class HttpManager {
|
|
|
1020
1054
|
}
|
|
1021
1055
|
|
|
1022
1056
|
_sendBatches(thePayload.batches, retryCount + 1, thePayload.isTeardown, _isUnloading ? EventSendType.SendBeacon : thePayload.sendType, SendRequestReason.Retry);
|
|
1023
|
-
}, _isUnloading,
|
|
1057
|
+
}, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount));
|
|
1024
1058
|
} else {
|
|
1025
1059
|
backOffTrans = true;
|
|
1060
|
+
if (_isUnloading) {
|
|
1061
|
+
// we are unloading so don't try and requeue the events otherwise let the events get requeued and resent during the backoff sending
|
|
1062
|
+
// This will also cause the events to be purged based on the priority (if necessary)
|
|
1063
|
+
reason = EventBatchNotificationReason.NonRetryableStatus;
|
|
1064
|
+
}
|
|
1026
1065
|
}
|
|
1027
1066
|
}
|
|
1028
1067
|
}
|
|
@@ -1144,8 +1183,9 @@ export class HttpManager {
|
|
|
1144
1183
|
try {
|
|
1145
1184
|
responseHandlers[i](responseText);
|
|
1146
1185
|
} catch (e) {
|
|
1147
|
-
_postManager.diagLog()
|
|
1148
|
-
|
|
1186
|
+
_throwInternal(_postManager.diagLog(),
|
|
1187
|
+
eLoggingSeverity.CRITICAL,
|
|
1188
|
+
_eExtendedInternalMessageId.PostResponseHandler,
|
|
1149
1189
|
"Response handler failed: " + e);
|
|
1150
1190
|
}
|
|
1151
1191
|
}
|
|
@@ -1172,8 +1212,9 @@ export class HttpManager {
|
|
|
1172
1212
|
try {
|
|
1173
1213
|
theAction.call(actions, theBatches, batchReason, isSyncRequest, sendType);
|
|
1174
1214
|
} catch (e) {
|
|
1175
|
-
_postManager.diagLog()
|
|
1176
|
-
|
|
1215
|
+
_throwInternal(_postManager.diagLog(),
|
|
1216
|
+
eLoggingSeverity.CRITICAL,
|
|
1217
|
+
_eInternalMessageId.NotificationException,
|
|
1177
1218
|
"send request notification failed: " + e);
|
|
1178
1219
|
}
|
|
1179
1220
|
}, sendSync || isSyncRequest, 0);
|