Skip to content

Commit

Permalink
Set a default timeout for requests
Browse files Browse the repository at this point in the history
  • Loading branch information
eablack committed Dec 18, 2024
1 parent e6524c4 commit 1bfe1d2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class HTTP<T> {
raw: false,
partial: false,
headers: {},
timeout: 5000,
}

static create(options: HTTPRequestOptions = {}): typeof HTTP {
Expand Down Expand Up @@ -390,10 +391,10 @@ export class HTTP<T> {
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 {
Expand Down

0 comments on commit 1bfe1d2

Please sign in to comment.