set-type -> mime-types

removes mime dependencies from the dep tree.
liberally sets charset because some express users complained about bad
browsers using the default charset.
This commit is contained in:
Jonathan Ong 2014-06-03 21:44:25 -07:00
parent c7f2d24851
commit 008f0554c6
7 changed files with 20 additions and 20 deletions

View file

@ -4,10 +4,10 @@
*/
var ensureErrorHandler = require('error-inject');
var getType = require('mime-types').contentType;
var isJSON = require('koa-is-json');
var escape = require('escape-html');
var onfinish = require('finished');
var getType = require('set-type');
var status = require('statuses');
var destroy = require('dethroy');
var http = require('http');

View file

@ -25,7 +25,7 @@
"statuses": "~1.0.1",
"accepts": "~1.0.0",
"type-is": "~1.2.0",
"set-type": "~1.0.0",
"mime-types": "~1.0.0",
"finished": "~1.1.1",
"co": "~3.0.2",
"debug": "*",

View file

@ -177,7 +177,7 @@ describe('app.respond', function(){
.expect(200)
.end(function(err, res){
if (err) return done(err);
res.should.have.header('Content-Type', 'application/json');
res.should.have.header('Content-Type', 'application/json; charset=utf-8');
res.should.have.header('Content-Length', '17');
assert(0 == res.text.length);
done();
@ -553,14 +553,14 @@ describe('app.respond', function(){
app.use(function *(){
this.body = fs.createReadStream('package.json');
this.set('Content-Type', 'application/json');
this.set('Content-Type', 'application/json; charset=utf-8');
});
var server = app.listen();
request(server)
.get('/')
.expect('Content-Type', 'application/json')
.expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){
if (err) return done(err);
var pkg = require('../package');
@ -576,14 +576,14 @@ describe('app.respond', function(){
app.use(function *(){
this.body = 'hello';
this.body = fs.createReadStream('package.json');
this.set('Content-Type', 'application/json');
this.set('Content-Type', 'application/json; charset=utf-8');
});
var server = app.listen();
request(server)
.get('/')
.expect('Content-Type', 'application/json')
.expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){
if (err) return done(err);
var pkg = require('../package');
@ -599,14 +599,14 @@ describe('app.respond', function(){
app.use(function *(){
this.length = fs.readFileSync('package.json').length;
this.body = fs.createReadStream('package.json');
this.set('Content-Type', 'application/json');
this.set('Content-Type', 'application/json; charset=utf-8');
});
var server = app.listen();
request(server)
.get('/')
.expect('Content-Type', 'application/json')
.expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){
if (err) return done(err);
var pkg = require('../package');
@ -624,14 +624,14 @@ describe('app.respond', function(){
var stream = fs.createReadStream('package.json');
this.body = stream;
this.body = stream;
this.set('Content-Type', 'application/json');
this.set('Content-Type', 'application/json; charset=utf-8');
});
var server = app.listen();
request(server)
.get('/')
.expect('Content-Type', 'application/json')
.expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){
if (err) return done(err);
var pkg = require('../package');
@ -645,7 +645,7 @@ describe('app.respond', function(){
var app = koa();
app.use(function *(){
this.set('Content-Type', 'application/json');
this.set('Content-Type', 'application/json; charset=utf-8');
this.body = fs.createReadStream('does not exist');
});
@ -703,7 +703,7 @@ describe('app.respond', function(){
request(server)
.get('/')
.expect('Content-Type', 'application/json')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect('{"hello":"world"}', done);
})
})

View file

@ -79,7 +79,7 @@ describe('ctx.is(type)', function(){
ctx.is('jpeg').should.be.false;
ctx.is('.jpeg').should.be.false;
ctx.is('text/*', 'application/*').should.be.false;
ctx.is('text/html', 'text/plain', 'application/json').should.be.false;
ctx.is('text/html', 'text/plain', 'application/json; charset=utf-8').should.be.false;
})
})

View file

@ -20,7 +20,7 @@ describe('res.body=', function(){
assert('text/html; charset=utf-8' == res.header['content-type']);
res.body = { foo: 'bar' };
assert('application/json' == res.header['content-type']);
assert('application/json; charset=utf-8' == res.header['content-type']);
})
})
@ -126,7 +126,7 @@ describe('res.body=', function(){
it('should default to json', function(){
var res = response();
res.body = { foo: 'bar' };
assert('application/json' == res.header['content-type']);
assert('application/json; charset=utf-8' == res.header['content-type']);
})
})
})

View file

@ -42,7 +42,7 @@ describe('res.status=', function(){
app.use(function *(){
this.body = { foo: 'bar' };
this.set('Content-Type', 'application/json');
this.set('Content-Type', 'application/json; charset=utf-8');
this.set('Content-Length', '15');
this.set('Transfer-Encoding', 'chunked');
this.status = status;
@ -69,7 +69,7 @@ describe('res.status=', function(){
app.use(function *(){
this.status = status;
this.body = { foo: 'bar' };
this.set('Content-Type', 'application/json');
this.set('Content-Type', 'application/json; charset=utf-8');
this.set('Content-Length', '15');
this.set('Transfer-Encoding', 'chunked');
});

View file

@ -17,7 +17,7 @@ describe('ctx.type=', function(){
var ctx = context();
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; charset=utf-8');
})
})