Revert "add response.charset accessor and ctx.charset alias"

This reverts commit 94413b1bd4.
This commit is contained in:
TJ Holowaychuk 2014-03-06 18:05:01 -08:00
parent c50012a636
commit b1f0abd16d
5 changed files with 2 additions and 85 deletions

View File

@ -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()`

View File

@ -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`.

View File

@ -151,7 +151,6 @@ delegate(proto, 'response')
.access('body')
.access('length')
.access('type')
.access('charset')
.getter('headerSent')
.getter('writable')
.setter('lastModified')

View File

@ -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.
*

View File

@ -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');
})
})
})