UNPKG

@sap-cloud-sdk/core

Version:
30 lines 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProtocolOrDefault = void 0; var util_1 = require("@sap-cloud-sdk/util"); var protocol_1 = require("./protocol"); var logger = (0, util_1.createLogger)({ package: 'core', messageContext: 'get-protocol' }); /** * Extracts the http protocol from the destination URL. The default value is http if no protocol is given. * @param destination - URL of this destination is parsed * @throws Error in case a unsupported protocol is given in the destination URL like rfc://example.com. * @returns The protocol, either https or http. */ function getProtocolOrDefault(destination) { var _a, _b; var protocol = (_b = (_a = destination === null || destination === void 0 ? void 0 : destination.url) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.split('://'); if (!protocol || protocol.length === 1) { logger.warn("URL of the provided destination (".concat(destination.url, ") has no protocol specified! Assuming HTTPS.")); return protocol_1.Protocol.HTTPS; } var casted = protocol_1.Protocol.of(protocol[0]); if (casted) { return casted; } throw new Error("Protocol of the provided destination (".concat(destination.url, ") is not supported! Currently only HTTP and HTTPS are supported.")); } exports.getProtocolOrDefault = getProtocolOrDefault; //# sourceMappingURL=get-protocol.js.map