From 6fb32165e3ca96f34869c2b560b93482e5d8a03f Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Thu, 22 Aug 2013 21:10:59 -0700 Subject: [PATCH] fix .status= case sensitivity --- docs/api.md | 2 +- lib/context.js | 2 +- test/context.js | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/api.md b/docs/api.md index cee90f7..f19fca4 100644 --- a/docs/api.md +++ b/docs/api.md @@ -129,7 +129,7 @@ app.context({ ### ctx.status= - Set response status via numeric code or string: + Set response status via numeric code or case-insensitive string: - 100 "continue" - 101 "switching protocols" diff --git a/lib/context.js b/lib/context.js index 51e847c..5e3fafa 100644 --- a/lib/context.js +++ b/lib/context.js @@ -66,7 +66,7 @@ module.exports = { set status(val) { if ('string' == typeof val) { - var n = statuses[val]; + var n = statuses[val.toLowerCase()]; if (!n) throw new Error(statusError(val)); val = n; } diff --git a/test/context.js b/test/context.js index 9f94fe7..b332024 100644 --- a/test/context.js +++ b/test/context.js @@ -156,6 +156,12 @@ describe('ctx.status=', function(){ ctx.status = 'forbidden'; ctx.status.should.equal(403); }) + + it('should be case-insensitive', function(){ + var ctx = context(); + ctx.status = 'ForBidden'; + ctx.status.should.equal(403); + }) }) describe('and invalid', function(){