Skip to content

Commit

Permalink
Setting res.statusCode from error(), conditionally setting `x-res…
Browse files Browse the repository at this point in the history
…ponse-time` response header from `res.send()`
  • Loading branch information
avoidwork committed Jan 3, 2021
1 parent d074291 commit eb9c9db
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -230,6 +230,7 @@ class Woodland extends EventEmitter {
}

res.header("content-type", "text/plain; charset=utf-8");
res.statusCode = status;
res.send(output, status);
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit eb9c9db

Please sign in to comment.