3 const replay = require('request-replay')
4 const request = require('request')
6 const constants = require('../initializers/constants')
7 const peertubeCrypto = require('./peertube-crypto')
14 function makeRetryRequest (params, callback) {
16 request(params, callback),
18 retries: constants.RETRY_REQUESTS,
21 errorCodes: [ 'EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED' ]
26 function makeSecureRequest (params, callback) {
27 const requestParams = {
28 url: constants.REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path
31 if (params.method !== 'POST') {
32 return callback(new Error('Cannot make a secure request with a non POST method.'))
35 requestParams.json = {}
37 // Add signature if it is specified in the params
38 if (params.sign === true) {
39 const host = constants.CONFIG.WEBSERVER.HOST
43 dataToSign = params.data
45 // We do not have data to sign so we just take our host
46 // It is not ideal but the connection should be in HTTPS
50 requestParams.json.signature = {
51 host, // Which host we pretend to be
52 signature: peertubeCrypto.sign(dataToSign)
56 // If there are data informations
58 requestParams.json.data = params.data
61 console.log(requestParams.json.data)
63 request.post(requestParams, callback)
66 // ---------------------------------------------------------------------------
68 module.exports = requests