change ctx.length and ctx.type to always delegate to response object [breaking change]

This commit is contained in:
TJ Holowaychuk 2014-02-14 09:16:39 -08:00
parent 4efd645bfd
commit 08149052fa
2 changed files with 8 additions and 7 deletions

View file

@ -149,11 +149,11 @@ delegate(proto, 'response')
.method('set') .method('set')
.access('status') .access('status')
.access('body') .access('body')
.access('length')
.access('type')
.getter('headerSent') .getter('headerSent')
.setter('lastModified') .setter('lastModified')
.setter('length') .setter('etag');
.setter('etag')
.setter('type');
/** /**
* Request delegation. * Request delegation.
@ -175,13 +175,11 @@ delegate(proto, 'request')
.access('path') .access('path')
.access('host') .access('host')
.access('url') .access('url')
.getter('length')
.getter('subdomains') .getter('subdomains')
.getter('protocol') .getter('protocol')
.getter('header') .getter('header')
.getter('secure') .getter('secure')
.getter('stale') .getter('stale')
.getter('fresh') .getter('fresh')
.getter('type')
.getter('ips') .getter('ips')
.getter('ip'); .getter('ip');

View file

@ -7,6 +7,7 @@ describe('ctx.type=', function(){
it('should set the Content-Type', function(){ it('should set the Content-Type', function(){
var ctx = context(); var ctx = context();
ctx.type = 'text/plain'; ctx.type = 'text/plain';
ctx.type.should.equal('text/plain');
ctx.response.header['content-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(){ it('should lookup the mime', function(){
var ctx = context(); var ctx = context();
ctx.type = 'json'; ctx.type = 'json';
ctx.type.should.equal('application/json');
ctx.response.header['content-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(){ describe('with no Content-Type', function(){
it('should return null', function(){ it('should return null', function(){
var ctx = context(); var ctx = context();
// TODO: this is lame
assert(null == ctx.type); assert(null == ctx.type);
}) })
}) })
@ -31,8 +34,8 @@ describe('ctx.type', function(){
describe('with a Content-Type', function(){ describe('with a Content-Type', function(){
it('should return the mime', function(){ it('should return the mime', function(){
var ctx = context(); var ctx = context();
ctx.req.headers['content-type'] = 'text/html; charset=utf8'; ctx.type = 'json';
ctx.type.should.equal('text/html'); ctx.type.should.equal('application/json');
}) })
}) })
}) })