From 1bfe1d2b6c67e444e563b94b65eddb56bd564aad Mon Sep 17 00:00:00 2001 From: Eric Black Date: Wed, 18 Dec 2024 13:15:37 -0800 Subject: [PATCH] Set a default timeout for requests --- package.json | 2 +- src/http.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8e7f4ca..468ca0c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "prepare": "rm -rf lib && tsc", "pretest": "tsc", "posttest": "eslint . --ext .ts", - "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js" + "test": "jest" }, "types": "./lib/http.d.ts" } diff --git a/src/http.ts b/src/http.ts index f9cb53c..f44ecda 100644 --- a/src/http.ts +++ b/src/http.ts @@ -100,6 +100,7 @@ export class HTTP { raw: false, partial: false, headers: {}, + timeout: 5000, } static create(options: HTTPRequestOptions = {}): typeof HTTP { @@ -390,10 +391,10 @@ export class HTTP { debug(`← ${this.method} ${this.url} TIMED OUT`) this.request.destroy() }) + this.request.on('timeout', reject) } this.request.on('error', reject) - this.request.on('timeout', reject) if (this.options.body && deps.isStream.readable(this.options.body)) { this.options.body.pipe(this.request) } else {