Merge pull request #94 from jwulf/https

Support https for projections
This commit is contained in:
Nicolas Dextraze 2022-10-19 13:48:32 -04:00 committed by GitHub
commit 6159cd56b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
const http = require('http');
const https = require('https');
const url = require('url');
const util = require('util');
const ProjectionCommandFailedError = require('../errors/projectionCommandFailedError');
@ -112,6 +113,7 @@ ProjectionsClient.prototype.delete = function(httpEndPoint, name, deleteEmittedS
ProjectionsClient.prototype.request = function(method, _url, data, userCredentials, expectedCode) {
const options = url.parse(_url);
const httplib = options.protocol === 'https:' ? https : http;
options.method = method;
if (userCredentials) {
options.auth = [userCredentials.username, userCredentials.password].join(':');
@ -121,7 +123,7 @@ ProjectionsClient.prototype.request = function(method, _url, data, userCredentia
const timeout = setTimeout(function () {
reject(new Error(util.format('Request timed out for %s on %s', method, _url)))
}, self._operationTimeout);
const req = http.request(options, function (res) {
const req = httplib.request(options, function (res) {
const hasExpectedCode = res.statusCode === expectedCode;
var result = '';
res.setEncoding('utf8');