]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/requests.js
Server: we don't need the video name when removing a remote video
[github/Chocobozzz/PeerTube.git] / server / helpers / requests.js
CommitLineData
9f10b292 1'use strict'
dac0a531 2
f0f5567b 3const replay = require('request-replay')
528a9efa 4const request = require('request')
dac0a531 5
f0f5567b 6const constants = require('../initializers/constants')
5f698b82 7const peertubeCrypto = require('./peertube-crypto')
dac0a531 8
f0f5567b 9const requests = {
c4403b29
C
10 makeRetryRequest,
11 makeSecureRequest
9f10b292 12}
dac0a531 13
528a9efa
C
14function makeRetryRequest (params, callback) {
15 replay(
16 request(params, callback),
17 {
18 retries: constants.RETRY_REQUESTS,
19 factor: 3,
20 maxTimeout: Infinity,
21 errorCodes: [ 'EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED' ]
22 }
23 )
24}
dac0a531 25
528a9efa 26function makeSecureRequest (params, callback) {
528a9efa 27 const requestParams = {
49abbbbe 28 url: constants.REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path
9f10b292 29 }
dac0a531 30
528a9efa
C
31 // Add data with POST requst ?
32 if (params.method === 'POST') {
33 requestParams.json = {}
dac0a531 34
528a9efa
C
35 // Add signature if it is specified in the params
36 if (params.sign === true) {
49abbbbe
C
37 const host = constants.CONFIG.WEBSERVER.HOST
38
528a9efa 39 requestParams.json.signature = {
49abbbbe
C
40 host,
41 signature: peertubeCrypto.sign(host)
528a9efa 42 }
9f10b292 43 }
dac0a531 44
528a9efa
C
45 // If there are data informations
46 if (params.data) {
38d78e5b
C
47 requestParams.json.data = params.data
48 request.post(requestParams, callback)
9f10b292 49 } else {
528a9efa
C
50 // No data
51 request.post(requestParams, callback)
9f10b292 52 }
528a9efa
C
53 } else {
54 request.get(requestParams, callback)
55 }
9f10b292 56}
dac0a531 57
9f10b292 58// ---------------------------------------------------------------------------
dac0a531 59
9f10b292 60module.exports = requests