aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/requests.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r--server/helpers/requests.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index 48b1fd703..b40fc8e39 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -6,9 +6,15 @@ import {
6 REMOTE_SCHEME, 6 REMOTE_SCHEME,
7 CONFIG 7 CONFIG
8} from '../initializers' 8} from '../initializers'
9import { PodInstance } from '../models'
9import { sign } from './peertube-crypto' 10import { sign } from './peertube-crypto'
10 11
11function makeRetryRequest (params, callback) { 12type MakeRetryRequestParams = {
13 url: string,
14 method: 'GET'|'POST',
15 json: Object
16}
17function makeRetryRequest (params: MakeRetryRequestParams, callback: request.RequestCallback) {
12 replay( 18 replay(
13 request(params, callback), 19 request(params, callback),
14 { 20 {
@@ -20,14 +26,21 @@ function makeRetryRequest (params, callback) {
20 ) 26 )
21} 27}
22 28
23function makeSecureRequest (params, callback) { 29type MakeSecureRequestParams = {
30 method: 'GET'|'POST'
31 toPod: PodInstance
32 path: string
33 sign: boolean
34 data?: Object
35}
36function makeSecureRequest (params: MakeSecureRequestParams, callback: request.RequestCallback) {
24 const requestParams = { 37 const requestParams = {
25 url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path, 38 url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path,
26 json: {} 39 json: {}
27 } 40 }
28 41
29 if (params.method !== 'POST') { 42 if (params.method !== 'POST') {
30 return callback(new Error('Cannot make a secure request with a non POST method.')) 43 return callback(new Error('Cannot make a secure request with a non POST method.'), null, null)
31 } 44 }
32 45
33 // Add signature if it is specified in the params 46 // Add signature if it is specified in the params