diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-07 16:57:28 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-07 18:23:18 +0200 |
commit | 709756b8e183f67ef9bf8f7bc149af4736260350 (patch) | |
tree | dc5e52878a6f56c69a4589e058e830c57b025a05 /server/helpers/requests.ts | |
parent | 18c8e945089bff49d2c617c411c8a8f4575989ad (diff) | |
download | PeerTube-709756b8e183f67ef9bf8f7bc149af4736260350.tar.gz PeerTube-709756b8e183f67ef9bf8f7bc149af4736260350.tar.zst PeerTube-709756b8e183f67ef9bf8f7bc149af4736260350.zip |
Async signature and various fixes
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r-- | server/helpers/requests.ts | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index b31074373..183f6df0d 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -33,7 +33,6 @@ type MakeSecureRequestParams = { | |||
33 | method: 'GET'|'POST' | 33 | method: 'GET'|'POST' |
34 | toPod: PodInstance | 34 | toPod: PodInstance |
35 | path: string | 35 | path: string |
36 | sign: boolean | ||
37 | data?: Object | 36 | data?: Object |
38 | } | 37 | } |
39 | function makeSecureRequest (params: MakeSecureRequestParams) { | 38 | function makeSecureRequest (params: MakeSecureRequestParams) { |
@@ -47,31 +46,30 @@ function makeSecureRequest (params: MakeSecureRequestParams) { | |||
47 | return rej(new Error('Cannot make a secure request with a non POST method.')) | 46 | return rej(new Error('Cannot make a secure request with a non POST method.')) |
48 | } | 47 | } |
49 | 48 | ||
50 | // Add signature if it is specified in the params | 49 | const host = CONFIG.WEBSERVER.HOST |
51 | if (params.sign === true) { | ||
52 | const host = CONFIG.WEBSERVER.HOST | ||
53 | 50 | ||
54 | let dataToSign | 51 | let dataToSign |
55 | if (params.data) { | 52 | if (params.data) { |
56 | dataToSign = params.data | 53 | dataToSign = params.data |
57 | } else { | 54 | } else { |
58 | // We do not have data to sign so we just take our host | 55 | // We do not have data to sign so we just take our host |
59 | // It is not ideal but the connection should be in HTTPS | 56 | // It is not ideal but the connection should be in HTTPS |
60 | dataToSign = host | 57 | dataToSign = host |
61 | } | 58 | } |
62 | 59 | ||
60 | sign(dataToSign).then(signature => { | ||
63 | requestParams.json['signature'] = { | 61 | requestParams.json['signature'] = { |
64 | host, // Which host we pretend to be | 62 | host, // Which host we pretend to be |
65 | signature: sign(dataToSign) | 63 | signature |
66 | } | 64 | } |
67 | } | ||
68 | 65 | ||
69 | // If there are data informations | 66 | // If there are data informations |
70 | if (params.data) { | 67 | if (params.data) { |
71 | requestParams.json['data'] = params.data | 68 | requestParams.json['data'] = params.data |
72 | } | 69 | } |
73 | 70 | ||
74 | request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body })) | 71 | request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body })) |
72 | }) | ||
75 | }) | 73 | }) |
76 | } | 74 | } |
77 | 75 | ||