mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-24 21:06:43 -06:00
ActivityPubのHTTPリクエストの強化 (#2820)
* Fix error handling in AP deliver * Set timeout to resolver * Tune looks
This commit is contained in:
parent
baf9b65801
commit
f243ce66e7
3 changed files with 24 additions and 13 deletions
|
@ -7,19 +7,18 @@ export default async (job: bq.Job, done: any): Promise<void> => {
|
|||
await request(job.data.user, job.data.to, job.data.content);
|
||||
done();
|
||||
} catch (res) {
|
||||
if (res == null || !res.hasOwnProperty('statusCode')) {
|
||||
console.warn(`deliver failed (unknown): ${res}`);
|
||||
return done();
|
||||
}
|
||||
|
||||
if (res.statusCode == null) return done();
|
||||
if (res.statusCode >= 400 && res.statusCode < 500) {
|
||||
// HTTPステータスコード4xxはクライアントエラーであり、それはつまり
|
||||
// 何回再送しても成功することはないということなのでエラーにはしないでおく
|
||||
done();
|
||||
if (res != null && res.hasOwnProperty('statusCode')) {
|
||||
if (res.statusCode >= 400 && res.statusCode < 500) {
|
||||
// HTTPステータスコード4xxはクライアントエラーであり、それはつまり
|
||||
// 何回再送しても成功することはないということなのでエラーにはしないでおく
|
||||
done();
|
||||
} else {
|
||||
console.warn(`deliver failed: ${res.statusCode} ${res.statusMessage} to=${job.data.to}`);
|
||||
done(res.statusMessage);
|
||||
}
|
||||
} else {
|
||||
console.warn(`deliver failed: ${res.statusMessage}`);
|
||||
done(res.statusMessage);
|
||||
console.warn(`deliver failed: ${res} to=${job.data.to}`);
|
||||
done();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -12,6 +12,8 @@ const log = debug('misskey:activitypub:deliver');
|
|||
export default (user: ILocalUser, url: string, object: any) => new Promise((resolve, reject) => {
|
||||
log(`--> ${url}`);
|
||||
|
||||
const timeout = 10 * 1000;
|
||||
|
||||
const { protocol, hostname, port, pathname, search } = new URL(url);
|
||||
|
||||
const data = JSON.stringify(object);
|
||||
|
@ -26,6 +28,7 @@ export default (user: ILocalUser, url: string, object: any) => new Promise((reso
|
|||
port,
|
||||
method: 'POST',
|
||||
path: pathname + search,
|
||||
timeout,
|
||||
headers: {
|
||||
'User-Agent': config.user_agent,
|
||||
'Content-Type': 'application/activity+json',
|
||||
|
@ -35,7 +38,7 @@ export default (user: ILocalUser, url: string, object: any) => new Promise((reso
|
|||
log(`${url} --> ${res.statusCode}`);
|
||||
|
||||
if (res.statusCode >= 400) {
|
||||
reject();
|
||||
reject(res);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
|
@ -53,5 +56,12 @@ export default (user: ILocalUser, url: string, object: any) => new Promise((reso
|
|||
sig = sig.replace(/^Signature /, '');
|
||||
req.setHeader('Signature', sig);
|
||||
|
||||
req.on('timeout', () => req.abort());
|
||||
|
||||
req.on('error', e => {
|
||||
if (req.aborted) reject('timeout');
|
||||
reject(e);
|
||||
});
|
||||
|
||||
req.end(data);
|
||||
});
|
||||
|
|
|
@ -7,6 +7,7 @@ const log = debug('misskey:activitypub:resolver');
|
|||
|
||||
export default class Resolver {
|
||||
private history: Set<string>;
|
||||
private timeout = 10 * 1000;
|
||||
|
||||
constructor() {
|
||||
this.history = new Set();
|
||||
|
@ -50,6 +51,7 @@ export default class Resolver {
|
|||
|
||||
const object = await request({
|
||||
url: value,
|
||||
timeout: this.timeout,
|
||||
headers: {
|
||||
'User-Agent': config.user_agent,
|
||||
Accept: 'application/activity+json, application/ld+json'
|
||||
|
|
Loading…
Reference in a new issue