+ PeerTubeRequestOptions,
+
+ doRequest,
+ doJSONRequest,
+ doRequestAndSaveToFile,
+ isBinaryResponse,
+ getAgent,
+ findLatestRedirection,
+ peertubeGot
+}
+
+// ---------------------------------------------------------------------------
+
+function buildGotOptions (options: PeerTubeRequestOptions) {
+ const { activityPub, bodyKBLimit = 1000 } = options
+
+ const context = { bodyKBLimit, httpSignature: options.httpSignature }
+
+ let headers = options.headers || {}
+
+ if (!headers.date) {
+ headers = { ...headers, date: new Date().toUTCString() }
+ }
+
+ if (activityPub && !headers.accept) {
+ headers = { ...headers, accept: ACTIVITY_PUB.ACCEPT_HEADER }
+ }
+
+ return {
+ method: options.method,
+ dnsCache: true,
+ timeout: options.timeout ?? REQUEST_TIMEOUTS.DEFAULT,
+ json: options.json,
+ searchParams: options.searchParams,
+ retry: 2,
+ headers,
+ context
+ }
+}
+
+function buildRequestError (error: RequestError) {
+ const newError: PeerTubeRequestError = new Error(error.message)
+ newError.name = error.name
+ newError.stack = error.stack
+
+ if (error.response) {
+ newError.responseBody = error.response.body
+ newError.responseHeaders = error.response.headers
+ newError.statusCode = error.response.statusCode
+ }
+
+ return newError