Innovenergy_trunk/frontend/node_modules/testcafe/lib/test-run/request/process-response-data.js

24 lines
3.7 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.processResponseData = void 0;
const http_headers_1 = __importDefault(require("../../utils/http-headers"));
const content_types_1 = __importDefault(require("../../assets/content-types"));
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
async function processResponseData(response, rawResponse = false) {
if (rawResponse)
return response;
const data = await (0, testcafe_hammerhead_1.promisifyStream)(response);
if (!response.headers[http_headers_1.default.contentType])
return data;
if (response.headers[http_headers_1.default.contentType].startsWith(content_types_1.default.textPlain) ||
response.headers[http_headers_1.default.contentType].startsWith(content_types_1.default.textHtml))
return data.toString('utf8');
if (response.headers[http_headers_1.default.contentType].startsWith(content_types_1.default.json))
return data.length ? JSON.parse(data.toString('utf8')) : '';
return data;
}
exports.processResponseData = processResponseData;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvY2Vzcy1yZXNwb25zZS1kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3Rlc3QtcnVuL3JlcXVlc3QvcHJvY2Vzcy1yZXNwb25zZS1kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUNBLDRFQUFvRDtBQUNwRCwrRUFBdUQ7QUFDdkQsNkRBQXNEO0FBRy9DLEtBQUssVUFBVSxtQkFBbUIsQ0FBRSxRQUF5QixFQUFFLFdBQVcsR0FBRyxLQUFLO0lBQ3JGLElBQUksV0FBVztRQUNYLE9BQU8sUUFBUSxDQUFDO0lBRXBCLE1BQU0sSUFBSSxHQUFHLE1BQU0sSUFBQSxxQ0FBZSxFQUFDLFFBQVEsQ0FBQyxDQUFDO0lBRTdDLElBQUksQ0FBQyxRQUFRLENBQUMsT0FBTy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