1 import * as replay from 'request-replay'
2 import * as request from 'request'
8 } from '../initializers'
9 import { sign } from './peertube-crypto'
11 function makeRetryRequest (params, callback) {
13 request(params, callback),
15 retries: RETRY_REQUESTS,
18 errorCodes: [ 'EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED' ]
23 function makeSecureRequest (params, callback) {
24 const requestParams = {
25 url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path,
29 if (params.method !== 'POST') {
30 return callback(new Error('Cannot make a secure request with a non POST method.'))
33 // Add signature if it is specified in the params
34 if (params.sign === true) {
35 const host = CONFIG.WEBSERVER.HOST
39 dataToSign = params.data
41 // We do not have data to sign so we just take our host
42 // It is not ideal but the connection should be in HTTPS
46 requestParams.json['signature'] = {
47 host, // Which host we pretend to be
48 signature: sign(dataToSign)
52 // If there are data informations
54 requestParams.json['data'] = params.data
57 request.post(requestParams, callback)
60 // ---------------------------------------------------------------------------