123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- Object.defineProperty(exports, '__esModule', { value: true });
- const core = require('@sentry/core');
- const utils = require('@sentry/utils');
- /**
- * The DONE ready state for XmlHttpRequest
- *
- * Defining it here as a constant b/c XMLHttpRequest.DONE is not always defined
- * (e.g. during testing, it is `undefined`)
- *
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState}
- */
- const XHR_READYSTATE_DONE = 4;
- /**
- * Creates a Transport that uses the XMLHttpRequest API to send events to Sentry.
- */
- function makeXHRTransport(options) {
- function makeRequest(request) {
- return new utils.SyncPromise((resolve, reject) => {
- const xhr = new XMLHttpRequest();
- xhr.onerror = reject;
- xhr.onreadystatechange = () => {
- if (xhr.readyState === XHR_READYSTATE_DONE) {
- resolve({
- statusCode: xhr.status,
- headers: {
- 'x-sentry-rate-limits': xhr.getResponseHeader('X-Sentry-Rate-Limits'),
- 'retry-after': xhr.getResponseHeader('Retry-After'),
- },
- });
- }
- };
- xhr.open('POST', options.url);
- for (const header in options.headers) {
- if (Object.prototype.hasOwnProperty.call(options.headers, header)) {
- xhr.setRequestHeader(header, options.headers[header]);
- }
- }
- xhr.send(request.body);
- });
- }
- return core.createTransport(options, makeRequest);
- }
- exports.makeXHRTransport = makeXHRTransport;
- //# sourceMappingURL=xhr.js.map
|