From 08149052fa48a211ddf7c5ad9760ff376d9408cf Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Fri, 14 Feb 2014 09:16:39 -0800 Subject: [PATCH] change ctx.length and ctx.type to always delegate to response object [breaking change] --- lib/context.js | 8 +++----- test/response/type.js | 7 +++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/context.js b/lib/context.js index 088979d..1873a89 100644 --- a/lib/context.js +++ b/lib/context.js @@ -149,11 +149,11 @@ delegate(proto, 'response') .method('set') .access('status') .access('body') + .access('length') + .access('type') .getter('headerSent') .setter('lastModified') - .setter('length') - .setter('etag') - .setter('type'); + .setter('etag'); /** * Request delegation. @@ -175,13 +175,11 @@ delegate(proto, 'request') .access('path') .access('host') .access('url') - .getter('length') .getter('subdomains') .getter('protocol') .getter('header') .getter('secure') .getter('stale') .getter('fresh') - .getter('type') .getter('ips') .getter('ip'); diff --git a/test/response/type.js b/test/response/type.js index 95384c1..2fbceb5 100644 --- a/test/response/type.js +++ b/test/response/type.js @@ -7,6 +7,7 @@ describe('ctx.type=', function(){ it('should set the Content-Type', function(){ var ctx = context(); ctx.type = 'text/plain'; + ctx.type.should.equal('text/plain'); ctx.response.header['content-type'].should.equal('text/plain'); }) }) @@ -15,6 +16,7 @@ describe('ctx.type=', function(){ it('should lookup the mime', function(){ var ctx = context(); ctx.type = 'json'; + ctx.type.should.equal('application/json'); ctx.response.header['content-type'].should.equal('application/json'); }) }) @@ -24,6 +26,7 @@ describe('ctx.type', function(){ describe('with no Content-Type', function(){ it('should return null', function(){ var ctx = context(); + // TODO: this is lame assert(null == ctx.type); }) }) @@ -31,8 +34,8 @@ describe('ctx.type', function(){ describe('with a Content-Type', function(){ it('should return the mime', function(){ var ctx = context(); - ctx.req.headers['content-type'] = 'text/html; charset=utf8'; - ctx.type.should.equal('text/html'); + ctx.type = 'json'; + ctx.type.should.equal('application/json'); }) }) }) \ No newline at end of file