From eb9c9db21a7cefb4146136a9d603cf6549507275 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sat, 2 Jan 2021 20:33:44 -0500 Subject: [PATCH] Setting `res.statusCode` from `error()`, conditionally setting `x-response-time` response header from `res.send()` --- lib/woodland.js | 5 +++-- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/woodland.js b/lib/woodland.js index fc06da1..1a4eb51 100644 --- a/lib/woodland.js +++ b/lib/woodland.js @@ -128,8 +128,8 @@ class Woodland extends EventEmitter { if (res.headersSent === false) { [body, status, headers] = this.onsend(req, res, body, status, headers); - if (this.time) { - headers["x-response-time"] = `${ms(req.precise.stop().diff(), this.digit)}`; + if (this.time && res.getHeader("x-response-time") === void 0) { + res.header("x-response-time", `${ms(req.precise.stop().diff(), this.digit)}`); } if (pipeable(req.method, body)) { @@ -230,6 +230,7 @@ class Woodland extends EventEmitter { } res.header("content-type", "text/plain; charset=utf-8"); + res.statusCode = status; res.send(output, status); } diff --git a/package-lock.json b/package-lock.json index 75ea74b..fd82eeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "woodland", - "version": "16.0.3", + "version": "16.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "16.0.3", + "version": "16.0.4", "license": "BSD-3-Clause", "dependencies": { "mime-db": "^1.45.0", diff --git a/package.json b/package.json index b0a92e0..9b352ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "woodland", - "version": "16.0.3", + "version": "16.0.4", "description": "Lightweight HTTP router with automatic headers", "main": "index.js", "scripts": {