summaryrefslogtreecommitdiff
path: root/src/remote
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2020-04-09 23:42:23 +0900
committerGitHub <noreply@github.com>2020-04-09 23:42:23 +0900
commitd3c0f3c251e8371d78d953f32f7311a38f4a1bdb (patch)
treeef746ec79b4cc53ad15da2680b2e5d6280d39867 /src/remote
parentCreate aiscript.ja-JP.md (diff)
downloadmisskey-d3c0f3c251e8371d78d953f32f7311a38f4a1bdb.tar.gz
misskey-d3c0f3c251e8371d78d953f32f7311a38f4a1bdb.tar.bz2
misskey-d3c0f3c251e8371d78d953f32f7311a38f4a1bdb.zip
Use node-fetch instead of request (#6228)
* requestをnode-fetchになど * format * fix error * t * Fix test
Diffstat (limited to 'src/remote')
-rw-r--r--src/remote/activitypub/request.ts11
-rw-r--r--src/remote/activitypub/resolver.ts23
-rw-r--r--src/remote/webfinger.ts15
3 files changed, 6 insertions, 43 deletions
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<string>;
- 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<IWebFinger> {
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) {