X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Frequests.ts;h=d3c83d26e29f25dc78ac884e3cda2c3a2003e17e;hb=71de85be3beb5f5181e6338b1a7154c8cf65afd4;hp=5eb69486d4dbe11b3bbfda034a4950c4711343d1;hpb=b5c361089f03f4d459fa1cdc49ff66dee736af12;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 5eb69486d..d3c83d26e 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts @@ -2,7 +2,7 @@ import { createWriteStream, remove } from 'fs-extra' import got, { CancelableRequest, Options as GotOptions, RequestError } from 'got' import { join } from 'path' import { CONFIG } from '../initializers/config' -import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants' +import { ACTIVITY_PUB, PEERTUBE_VERSION, REQUEST_TIMEOUT, WEBSERVER } from '../initializers/constants' import { pipelinePromise } from './core-utils' import { processImage } from './image-utils' import { logger } from './logger' @@ -24,6 +24,7 @@ type PeerTubeRequestOptions = { key: string headers: string[] } + timeout?: number jsonResponse?: boolean } & Pick @@ -92,6 +93,10 @@ const peertubeGot = got.extend({ path }, httpSignatureOptions) } + }, + + (options: GotOptions) => { + options.timeout = REQUEST_TIMEOUT } ] } @@ -170,9 +175,11 @@ function buildGotOptions (options: PeerTubeRequestOptions) { let headers = options.headers || {} - headers = { ...headers, date: new Date().toUTCString() } + if (!headers.date) { + headers = { ...headers, date: new Date().toUTCString() } + } - if (activityPub) { + if (activityPub && !headers.accept) { headers = { ...headers, accept: ACTIVITY_PUB.ACCEPT_HEADER } } @@ -180,6 +187,7 @@ function buildGotOptions (options: PeerTubeRequestOptions) { method: options.method, json: options.json, searchParams: options.searchParams, + timeout: options.timeout ?? REQUEST_TIMEOUT, headers, context }