aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authormira.bat <97340105+irafire@users.noreply.github.com>2023-07-27 17:01:15 +0200
committerGitHub <noreply@github.com>2023-07-27 17:01:15 +0200
commitf862be2749b4f2d8dee99128d7e3064a69920e11 (patch)
tree20643166e07cb31ca3e0d05b4490000150b2f1c4 /server/helpers
parent787d822cd471d1e4bd5a37c687c78cd5f69d8645 (diff)
downloadPeerTube-f862be2749b4f2d8dee99128d7e3064a69920e11.tar.gz
PeerTube-f862be2749b4f2d8dee99128d7e3064a69920e11.tar.zst
PeerTube-f862be2749b4f2d8dee99128d7e3064a69920e11.zip
Add an option to sign federated fetches for mastodon compatibility (#5898)
* Fix player error modal Not hidden when we change the video * Correctly dispose player components * Sign cross-server fetch requests for mastodon AUTHORIZED_FETCH compatibilty * Add a remote fetch sign configuration knob * Federated fetches refactoring --------- Co-authored-by: Chocobozzz <me@florianbigard.com> Co-authored-by: ira <ira@foxgirl.space>
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