Use node-fetch instead of request (#6228)

* requestをnode-fetchになど

* format

* fix error

* t

* Fix test
This commit is contained in:
MeiMei
2020-04-09 23:42:23 +09:00
committed by GitHub
parent bb7edfee04
commit d3c0f3c251
12 changed files with 140 additions and 218 deletions

View File

@@ -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,

View File

@@ -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']) ?

View File

@@ -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) {