From 53ce7200e7b2aef3d6d670e6b15c25c11c678321 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Wed, 29 Jun 2016 22:12:22 -0400 Subject: [PATCH] Updating the default `onerror` handler with a `Content-Type` header --- lib/woodland.js | 2 +- package.json | 2 +- test/test.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/woodland.js b/lib/woodland.js index f1d5e3a..6517eb1 100644 --- a/lib/woodland.js +++ b/lib/woodland.js @@ -26,7 +26,7 @@ class Woodland { status = numeric ? Number(err.message) : 500, body = numeric ? http.STATUS_CODES[status] : err.message; - res.writeHead(status); + res.writeHead(status, {"Content-Type": "text/plain"}); res.end(body); }; this.onfinish = () => {}; diff --git a/package.json b/package.json index 2f1274b..9a9702b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "woodland", - "version": "1.0.5", + "version": "1.0.6", "description": "Lightweight HTTP/HTTPS router with virtual hosts", "main": "index.js", "scripts": { diff --git a/test/test.js b/test/test.js index 6cd9db5..c945ff7 100644 --- a/test/test.js +++ b/test/test.js @@ -59,6 +59,7 @@ describe("Invalid Requests", function () { .expectStatus(405) .expectHeader("Allow", "GET, HEAD, OPTIONS") .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Method Not Allowed/) .end(function (err) { if (err) throw err; @@ -72,6 +73,7 @@ describe("Invalid Requests", function () { .expectStatus(405) .expectHeader("Allow", "GET, HEAD, OPTIONS") .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Method Not Allowed/) .end(function (err) { if (err) throw err; @@ -85,6 +87,7 @@ describe("Invalid Requests", function () { .expectStatus(405) .expectHeader("Allow", "GET, HEAD, OPTIONS") .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Method Not Allowed/) .end(function (err) { if (err) throw err; @@ -98,6 +101,7 @@ describe("Invalid Requests", function () { .expectStatus(405) .expectHeader("Allow", "GET, HEAD, OPTIONS") .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Method Not Allowed/) .end(function (err) { if (err) throw err; @@ -111,6 +115,7 @@ describe("Invalid Requests", function () { .expectStatus(404) .expectHeader("Allow", undefined) .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Not Found/) .end(function (err) { if (err) throw err; @@ -124,6 +129,7 @@ describe("Invalid Requests", function () { .expectStatus(404) .expectHeader("Allow", undefined) .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Not Found/) .end(function (err) { if (err) throw err; @@ -137,6 +143,7 @@ describe("Invalid Requests", function () { .expectStatus(404) .expectHeader("Allow", undefined) .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Not Found/) .end(function (err) { if (err) throw err; @@ -151,6 +158,7 @@ describe("Invalid Requests", function () { .expectStatus(404) .expectHeader("Allow", undefined) .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Not Found/) .end(function (err) { if (err) throw err; @@ -164,6 +172,7 @@ describe("Invalid Requests", function () { .expectStatus(404) .expectHeader("Allow", undefined) .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Not Found/) .end(function (err) { if (err) throw err; @@ -177,6 +186,7 @@ describe("Invalid Requests", function () { .expectStatus(404) .expectHeader("Allow", undefined) .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Not Found/) .end(function (err) { if (err) throw err; @@ -190,6 +200,7 @@ describe("Invalid Requests", function () { .expectStatus(404) .expectHeader("Allow", undefined) .expectHeader("Cache-Control", "no-cache") + .expectHeader("Content-Type", "text/plain") .expectBody(/Not Found/) .end(function (err) { if (err) throw err;