UNPKG

@qaflag/core

Version:

Base requirements for the QA Flag library

50 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpResponse = void 0; const tough_cookie_1 = require("tough-cookie"); class HttpResponse { constructor(response, meta) { this.response = response; this.meta = meta; } get duration() { if (!this.meta.startTime || !this.meta.endTime) { throw 'Start time and end time of request were not set'; } return this.meta.endTime - this.meta.startTime; } get headers() { if (!this.response.headers) return []; return Object.entries(this.response.headers).map(([key, value]) => ({ key, value: Array.isArray(value) ? value.join(' | ') : value, })); } get trailers() { return this.response.trailers || {}; } get cookies() { const cookies = {}; if (!this.response.headers['set-cookie']) return cookies; const cookieHeaders = Array.isArray(this.response.headers['set-cookie']) ? this.response.headers['set-cookie'] : [this.response.headers['set-cookie']]; cookieHeaders .map(cookie => tough_cookie_1.Cookie.parse(cookie)) .forEach(cookie => { if (cookie !== undefined) cookies[cookie.key] = cookie; }); return cookies; } get status() { return { code: this.response.status, text: this.response.statusText }; } get data() { return this.response.data; } } exports.HttpResponse = HttpResponse; //# sourceMappingURL=http-response.js.map