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(){