+
+// ---------------------------------------------------------------------------
+
+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: REQUEST_TIMEOUT,
+ json: options.json,
+ searchParams: options.searchParams,
+ 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.statusCode = error.response.statusCode
+ }
+
+ return newError
+}