aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/requests.ts16
1 files changed, 5 insertions, 11 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index 201a7d7e3..1625d6e49 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -21,6 +21,7 @@ type PeerTubeRequestOptions = {
21 timeout?: number 21 timeout?: number
22 activityPub?: boolean 22 activityPub?: boolean
23 bodyKBLimit?: number // 1MB 23 bodyKBLimit?: number // 1MB
24
24 httpSignature?: { 25 httpSignature?: {
25 algorithm: string 26 algorithm: string
26 authorizationHeaderName: string 27 authorizationHeaderName: string
@@ -28,7 +29,10 @@ type PeerTubeRequestOptions = {
28 key: string 29 key: string
29 headers: string[] 30 headers: string[]
30 } 31 }
32
31 jsonResponse?: boolean 33 jsonResponse?: boolean
34
35 followRedirect?: boolean
32} & Pick<GotOptions, 'headers' | 'json' | 'method' | 'searchParams'> 36} & Pick<GotOptions, 'headers' | 'json' | 'method' | 'searchParams'>
33 37
34const peertubeGot = got.extend({ 38const peertubeGot = got.extend({
@@ -180,16 +184,6 @@ function isBinaryResponse (result: Response<any>) {
180 return BINARY_CONTENT_TYPES.has(result.headers['content-type']) 184 return BINARY_CONTENT_TYPES.has(result.headers['content-type'])
181} 185}
182 186
183async function findLatestRedirection (url: string, options: PeerTubeRequestOptions, iteration = 1) {
184 if (iteration > 10) throw new Error('Too much iterations to find final URL ' + url)
185
186 const { headers } = await peertubeGot(url, { followRedirect: false, ...buildGotOptions(options) })
187
188 if (headers.location) return findLatestRedirection(headers.location, options, iteration + 1)
189
190 return url
191}
192
193// --------------------------------------------------------------------------- 187// ---------------------------------------------------------------------------
194 188
195export { 189export {
@@ -200,7 +194,6 @@ export {
200 doRequestAndSaveToFile, 194 doRequestAndSaveToFile,
201 isBinaryResponse, 195 isBinaryResponse,
202 getAgent, 196 getAgent,
203 findLatestRedirection,
204 peertubeGot 197 peertubeGot
205} 198}
206 199
@@ -227,6 +220,7 @@ function buildGotOptions (options: PeerTubeRequestOptions) {
227 timeout: options.timeout ?? REQUEST_TIMEOUTS.DEFAULT, 220 timeout: options.timeout ?? REQUEST_TIMEOUTS.DEFAULT,
228 json: options.json, 221 json: options.json,
229 searchParams: options.searchParams, 222 searchParams: options.searchParams,
223 followRedirect: options.followRedirect,
230 retry: 2, 224 retry: 2,
231 headers, 225 headers,
232 context 226 context