UNPKG

@sap-cloud-sdk/connectivity

Version:

SAP Cloud SDK for JavaScript connectivity

29 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProtocolOrDefault = getProtocolOrDefault; const util_1 = require("@sap-cloud-sdk/util"); const protocol_1 = require("./protocol"); const logger = (0, util_1.createLogger)({ package: 'connectivity', 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. * @internal */ function getProtocolOrDefault(destination) { const urlParts = destination.url.toLowerCase()?.split('://'); if (!urlParts || urlParts.length === 1) { logger.warn(`URL of the provided destination (${destination.url}) has no protocol specified! Assuming HTTPS.`); return 'https'; } const protocol = (0, protocol_1.getProtocol)(urlParts[0]); if (!protocol) { throw new Error(`Protocol of the provided destination (${destination.url}) is not supported! Currently only HTTP and HTTPS are supported.`); } return protocol; } //# sourceMappingURL=get-protocol.js.map