X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Frequests.js;h=42786411725ce8980bd3d017497567eb1f10ccb9;hb=1d49e1e27d63db1dfc9a7fd28c9902f488831a89;hp=b0cda09fe02452a520072f230288148ae5af3bbe;hpb=38d78e5b82a30d1318e3cc2532b7ea22b8e163fa;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/requests.js b/server/helpers/requests.js index b0cda09fe..427864117 100644 --- a/server/helpers/requests.js +++ b/server/helpers/requests.js @@ -28,31 +28,39 @@ function makeSecureRequest (params, callback) { url: constants.REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path } - // Add data with POST requst ? - if (params.method === 'POST') { - requestParams.json = {} - - // Add signature if it is specified in the params - if (params.sign === true) { - const host = constants.CONFIG.WEBSERVER.HOST - - requestParams.json.signature = { - host, - signature: peertubeCrypto.sign(host) - } - } + if (params.method !== 'POST') { + return callback(new Error('Cannot make a secure request with a non POST method.')) + } + + requestParams.json = {} - // If there are data informations + // Add signature if it is specified in the params + if (params.sign === true) { + const host = constants.CONFIG.WEBSERVER.HOST + + let dataToSign if (params.data) { - requestParams.json.data = params.data - request.post(requestParams, callback) + dataToSign = dataToSign = params.data } else { - // No data - request.post(requestParams, callback) + // We do not have data to sign so we just take our host + // It is not ideal but the connection should be in HTTPS + dataToSign = host + } + + requestParams.json.signature = { + host, // Which host we pretend to be + signature: peertubeCrypto.sign(dataToSign) } - } else { - request.get(requestParams, callback) } + + // If there are data informations + if (params.data) { + requestParams.json.data = params.data + } + + console.log(requestParams.json.data) + + request.post(requestParams, callback) } // ---------------------------------------------------------------------------