UNPKG

aft-web-services

Version:

Automated Functional Testing (AFT) module for testing web services over HTTP and HTTPS

30 lines 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.httpData = void 0; const xml_1 = require("../helpers/xml"); class HttpData { constructor(xmlParser) { this._xmlParser = xmlParser !== null && xmlParser !== void 0 ? xmlParser : xml_1.XML.fromString; } /** * attempts to parse the contents of this `HttpResponse.data` into the specified * type * #### NOTE: * > attempts to read the `content-type` header and if it contains * `html` or `xml` it will parse the data string as XML, otherwise as JSON * @returns the contents of this `HttpResponse.data` string parsed into an object * of the specified type. */ as(response) { if (response.headers && response.headers['content-type']) { const contentType = response.headers['content-type']; if (contentType.match(/(xml|html)/) !== null) { const doc = this._xmlParser(response.data); return doc; } } return JSON.parse(response.data); } } exports.httpData = new HttpData(); //# sourceMappingURL=http-data.js.map