From 51314fa7366c08030f851d6244d17c3209347636 Mon Sep 17 00:00:00 2001 From: Alan Gutierrez Date: Fri, 19 May 2017 13:26:21 -0500 Subject: [PATCH] Fix missing status message in 0.10. --- reactor.js | 6 ++---- t/reactor.t.js | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/reactor.js b/reactor.js index 9caa63a..3796013 100644 --- a/reactor.js +++ b/reactor.js @@ -27,8 +27,6 @@ var coalesce = require('extant') // Do nothing. var nop = require('nop') -var MISSING = { 400: 'Bad Request', 500: 'Internal Server Error' } - function Constructor (object, dispatch) { this._object = object this._dispatch = dispatch @@ -174,7 +172,7 @@ Reactor.prototype._respond = cadence(function (async, envelope) { var result = vargs.shift() var statusCode = (typeof vargs[0] == 'number') ? vargs.shift() : 200 - var description = coalesce(http.STATUS_CODES[statusCode], MISSING[statusCode]) + var description = coalesce(http.STATUS_CODES[statusCode]) if (typeof vargs[0] == 'string') { description = vargs.shift() } @@ -192,7 +190,7 @@ Reactor.prototype._respond = cadence(function (async, envelope) { try { return rescue(/^reactor#http$/m, function (error) { var statusCode = error.statusCode - var description = coalesce(error.description, http.STATUS_CODES[statusCode], MISSING[statusCode]) + var description = coalesce(error.description, http.STATUS_CODES[statusCode]) var headers = coalesce(error.headers, {}) interrupt.assert(description != null, 'unknown.http.status', { statusCode: statusCode }) diff --git a/t/reactor.t.js b/t/reactor.t.js index ace912d..1855a44 100644 --- a/t/reactor.t.js +++ b/t/reactor.t.js @@ -6,6 +6,7 @@ function prove (async, assert) { var UserAgent = require('vizsla') var http = require('http') var connect = require('connect') + var coalesce = require('extant') var now = 0 function Service () { @@ -107,7 +108,8 @@ function prove (async, assert) { ua.fetch(session, { url: '/exception' }, async()) }, function (body, response) { assert(response.statusCode, 500, 'exception status code') - assert(response.statusMessage, 'Internal Server Error', 'exception status message') + // Node.js 0.10 does not parse the status messsage. + assert(coalesce(response.statusMessage, 'Internal Server Error'), 'Internal Server Error', 'exception status message') ua.fetch(session, { url: '/json' }, async()) }, function (body, response) { assert(body, { key: 'value' }, 'json') @@ -117,7 +119,7 @@ function prove (async, assert) { ua.fetch(session, { url: '/post', post: new Buffer('{') }, async()) }, function (body, response) { assert(response.statusCode, 400, 'cannot parse') - assert(response.statusMessage, 'Bad Request', 'cannot parse message') + assert(coalesce(response.statusMessage, 'Bad Request'), 'Bad Request', 'cannot parse message') ua.fetch(session, { url: '/callbacky' }, async()) }, function (body, response) { assert(body.toString(), 'x\n', 'callbacky')