From d3c0f3c251e8371d78d953f32f7311a38f4a1bdb Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Thu, 9 Apr 2020 23:42:23 +0900 Subject: Use node-fetch instead of request (#6228) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * requestをnode-fetchになど * format * fix error * t * Fix test --- src/remote/activitypub/request.ts | 11 ++--------- src/remote/activitypub/resolver.ts | 23 ++--------------------- src/remote/webfinger.ts | 15 ++------------- 3 files changed, 6 insertions(+), 43 deletions(-) (limited to 'src/remote') diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts index 0f87381a44..24540827b2 100644 --- a/src/remote/activitypub/request.ts +++ b/src/remote/activitypub/request.ts @@ -1,19 +1,12 @@ import * as https from 'https'; import { sign } from 'http-signature'; import * as crypto from 'crypto'; -import * as cache from 'lookup-dns-cache'; import config from '../../config'; import { ILocalUser } from '../../models/entities/user'; import { UserKeypairs } from '../../models'; import { ensure } from '../../prelude/ensure'; -import { HttpsProxyAgent } from 'https-proxy-agent'; - -const agent = config.proxy - ? new HttpsProxyAgent(config.proxy) - : new https.Agent({ - lookup: cache.lookup, - }); +import { httpsAgent } from '../../misc/fetch'; export default async (user: ILocalUser, url: string, object: any) => { const timeout = 10 * 1000; @@ -32,7 +25,7 @@ export default async (user: ILocalUser, url: string, object: any) => { await new Promise((resolve, reject) => { const req = https.request({ - agent, + agent: httpsAgent, protocol, hostname, port, diff --git a/src/remote/activitypub/resolver.ts b/src/remote/activitypub/resolver.ts index 8688b79a40..3847ea92ca 100644 --- a/src/remote/activitypub/resolver.ts +++ b/src/remote/activitypub/resolver.ts @@ -1,10 +1,8 @@ -import * as request from 'request-promise-native'; +import { getJson } from '../../misc/fetch'; import { IObject, isCollectionOrOrderedCollection, ICollection, IOrderedCollection } from './type'; -import config from '../../config'; export default class Resolver { private history: Set; - private timeout = 10 * 1000; constructor() { this.history = new Set(); @@ -41,24 +39,7 @@ export default class Resolver { this.history.add(value); - const object = await request({ - url: value, - proxy: config.proxy, - timeout: this.timeout, - forever: true, - headers: { - 'User-Agent': config.userAgent, - Accept: 'application/activity+json, application/ld+json' - }, - json: true - }).catch(e => { - const message = `${e.name}: ${e.message ? e.message.substr(0, 200) : undefined}, url=${value}`; - throw { - name: e.name, - statusCode: e.statusCode, - message, - }; - }); + const object = await getJson(value, 'application/activity+json, application/ld+json'); if (object == null || ( Array.isArray(object['@context']) ? diff --git a/src/remote/webfinger.ts b/src/remote/webfinger.ts index e19ef96a2f..04f978a35d 100644 --- a/src/remote/webfinger.ts +++ b/src/remote/webfinger.ts @@ -1,5 +1,4 @@ -import config from '../config'; -import * as request from 'request-promise-native'; +import { getJson } from '../misc/fetch'; import { query as urlQuery } from '../prelude/url'; type ILink = { @@ -15,17 +14,7 @@ type IWebFinger = { export default async function(query: string): Promise { const url = genUrl(query); - return await request({ - url, - proxy: config.proxy, - timeout: 10 * 1000, - forever: true, - headers: { - 'User-Agent': config.userAgent, - Accept: 'application/jrd+json, application/json' - }, - json: true - }); + return await getJson(url, 'application/jrd+json, application/json'); } function genUrl(query: string) { -- cgit v1.2.3-freya