diff options
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r-- | server/helpers/requests.ts | 19 |
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' |
9 | import { PodInstance } from '../models' | ||
9 | import { sign } from './peertube-crypto' | 10 | import { sign } from './peertube-crypto' |
10 | 11 | ||
11 | function makeRetryRequest (params, callback) { | 12 | type MakeRetryRequestParams = { |
13 | url: string, | ||
14 | method: 'GET'|'POST', | ||
15 | json: Object | ||
16 | } | ||
17 | function 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 | ||
23 | function makeSecureRequest (params, callback) { | 29 | type MakeSecureRequestParams = { |
30 | method: 'GET'|'POST' | ||
31 | toPod: PodInstance | ||
32 | path: string | ||
33 | sign: boolean | ||
34 | data?: Object | ||
35 | } | ||
36 | function 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 |