summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/request.ts
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2018-10-05 01:58:41 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2018-10-05 01:58:41 +0900
commitf243ce66e77d2a2eeee08d160b9d764c2d1084d5 (patch)
tree8cd34f0f1bff6323cf39ff3167346cca1380aeb0 /src/remote/activitypub/request.ts
parentImprove error handling of packaging functions (diff)
downloadsharkey-f243ce66e77d2a2eeee08d160b9d764c2d1084d5.tar.gz
sharkey-f243ce66e77d2a2eeee08d160b9d764c2d1084d5.tar.bz2
sharkey-f243ce66e77d2a2eeee08d160b9d764c2d1084d5.zip
ActivityPubのHTTPリクエストの強化 (#2820)
* Fix error handling in AP deliver * Set timeout to resolver * Tune looks
Diffstat (limited to 'src/remote/activitypub/request.ts')
-rw-r--r--src/remote/activitypub/request.ts12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts
index 07f0ecca8b..177b6f458e 100644
--- a/src/remote/activitypub/request.ts
+++ b/src/remote/activitypub/request.ts
@@ -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);
});