From b1f0abd16d6cc54d2f1617e28630f2134538881b Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Thu, 6 Mar 2014 18:05:01 -0800 Subject: [PATCH] Revert "add response.charset accessor and ctx.charset alias" This reverts commit 94413b1bd4f20b8c4b183c84166fdfb71087aff6. --- docs/api/context.md | 6 ++---- docs/api/response.md | 14 -------------- lib/context.js | 1 - lib/response.js | 25 ------------------------ test/response/charset.js | 41 ---------------------------------------- 5 files changed, 2 insertions(+), 85 deletions(-) delete mode 100644 test/response/charset.js diff --git a/docs/api/context.md b/docs/api/context.md index ce0fee9..d9c0aab 100644 --- a/docs/api/context.md +++ b/docs/api/context.md @@ -149,12 +149,10 @@ throw err; - `ctx.body=` - `ctx.status` - `ctx.status=` - - `ctx.length` - `ctx.length=` - - `ctx.type` + - `ctx.length` - `ctx.type=` - - `ctx.charset` - - `ctx.charset=` + - `ctx.type` - `ctx.headerSent` - `ctx.redirect()` - `ctx.attachment()` diff --git a/docs/api/response.md b/docs/api/response.md index f1aa379..86458f6 100644 --- a/docs/api/response.md +++ b/docs/api/response.md @@ -186,20 +186,6 @@ this.type = 'png'; when explicitly defined in full as `res.type = 'text/html'` no charset is assigned. -### res.charset - - Get response charset when present, or `undefined`: - -```js -this.type = 'text/plain; charset=utf-8'; -this.charset -// => "utf-8" -``` - -### res.charset= - - Set the response charset, overriding if present. - ### res.redirect(url, [alt]) Perform a [302] redirect to `url`. diff --git a/lib/context.js b/lib/context.js index 93de857..d0eed8d 100644 --- a/lib/context.js +++ b/lib/context.js @@ -151,7 +151,6 @@ delegate(proto, 'response') .access('body') .access('length') .access('type') - .access('charset') .getter('headerSent') .getter('writable') .setter('lastModified') diff --git a/lib/response.js b/lib/response.js index 2c75efc..07d8291 100644 --- a/lib/response.js +++ b/lib/response.js @@ -17,31 +17,6 @@ var extname = path.extname; module.exports = { - /** - * Set the charset. - * - * @param {String} val - * @api public - */ - - set charset(val) { - this.set('Content-Type', this.type + '; charset=' + val); - }, - - /** - * Get the charset when present or undefined. - * - * @return {String} - * @api public - */ - - get charset() { - // TODO: lame, we could have a generic param parsing lib - var type = this.get('Content-Type'); - var m = type.match(/charset *= *(\S+)/); - if (m) return m[1]; - }, - /** * Return the request socket. * diff --git a/test/response/charset.js b/test/response/charset.js deleted file mode 100644 index 83d3c10..0000000 --- a/test/response/charset.js +++ /dev/null @@ -1,41 +0,0 @@ - -var context = require('../context'); -var assert = require('assert'); - -describe('ctx.charset=', function(){ - describe('with no charset present', function(){ - it('should set it', function(){ - var ctx = context(); - ctx.type = 'text/plain'; - ctx.charset = 'utf8'; - ctx.response.get('Content-Type').should.equal('text/plain; charset=utf8'); - }) - }) - - describe('with a charset', function(){ - it('should set it', function(){ - var ctx = context(); - ctx.type = 'text/plain; charset=hey'; - ctx.charset = 'utf8'; - ctx.response.get('Content-Type').should.equal('text/plain; charset=utf8'); - }) - }) -}) - -describe('ctx.charset', function(){ - describe('with no charset present', function(){ - it('should return null', function(){ - var ctx = context(); - ctx.type = 'text/plain'; - assert(null == ctx.charset); - }) - }) - - describe('with a charset', function(){ - it('should return the charset', function(){ - var ctx = context(); - ctx.type = 'text'; - ctx.charset.should.equal('utf-8'); - }) - }) -}) \ No newline at end of file