Skip to content

Commit

Permalink
Fixing handling of redirects, updating test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Sep 4, 2019
1 parent cd701c6 commit 1f8c0c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
31 changes: 19 additions & 12 deletions lib/tenso.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,19 +508,26 @@ class Tenso extends Base {

this.headers(req, res, status, body, headers);

if (status !== 204 && status !== 304) {
if (body === null || typeof body.on !== "function") {
result = body;
headers["content-length"] = Buffer.byteLength(result);

if (req.method === "HEAD") {
result = "";
switch (status) {
case 204:
case 301:
case 302:
case 304:
case 307:
case 308:
result = "";
break;
default:
if (body === null || typeof body.on !== "function") {
result = body;
headers["content-length"] = Buffer.byteLength(result);

if (req.method === "HEAD") {
result = "";
}
} else {
result = body;
}
} else {
result = body;
}
} else {
result = "";
}

headers["x-response-time"] = ((req.timer.stopped.length === 0 ? req.timer.stop() : req.timer).diff() / 1e6).toFixed(2) + " ms";
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tenso",
"description": "Tensō is an HTTP/HTTP2 REST API framework",
"version": "12.0.0",
"version": "12.0.1",
"homepage": "http://avoidwork.github.io/tenso",
"author": "Jason Mulligan <[email protected]>",
"repository": {
Expand Down Expand Up @@ -58,7 +58,7 @@
"grunt-mocha-test": "^0.13.3",
"jsonwebtoken": "^8.5.1",
"mocha": "^6.2.0",
"tiny-httptest": "^1.1.0"
"tiny-httptest": "^1.1.1"
},
"keywords": [
"rest",
Expand Down

0 comments on commit 1f8c0c0

Please sign in to comment.