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.
master
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 ensureErrorHandler = require('error-inject');
var getType = require('mime-types').contentType;
var isJSON = require('koa-is-json'); var isJSON = require('koa-is-json');
var escape = require('escape-html'); var escape = require('escape-html');
var onfinish = require('finished'); var onfinish = require('finished');
var getType = require('set-type');
var status = require('statuses'); var status = require('statuses');
var destroy = require('dethroy'); var destroy = require('dethroy');
var http = require('http'); var http = require('http');

View File

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

View File

@ -177,7 +177,7 @@ describe('app.respond', function(){
.expect(200) .expect(200)
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); 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'); res.should.have.header('Content-Length', '17');
assert(0 == res.text.length); assert(0 == res.text.length);
done(); done();
@ -553,14 +553,14 @@ describe('app.respond', function(){
app.use(function *(){ app.use(function *(){
this.body = fs.createReadStream('package.json'); 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(); var server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json') .expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
var pkg = require('../package'); var pkg = require('../package');
@ -576,14 +576,14 @@ describe('app.respond', function(){
app.use(function *(){ app.use(function *(){
this.body = 'hello'; this.body = 'hello';
this.body = fs.createReadStream('package.json'); 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(); var server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json') .expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
var pkg = require('../package'); var pkg = require('../package');
@ -599,14 +599,14 @@ describe('app.respond', function(){
app.use(function *(){ app.use(function *(){
this.length = fs.readFileSync('package.json').length; this.length = fs.readFileSync('package.json').length;
this.body = fs.createReadStream('package.json'); 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(); var server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json') .expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
var pkg = require('../package'); var pkg = require('../package');
@ -624,14 +624,14 @@ describe('app.respond', function(){
var stream = fs.createReadStream('package.json'); var stream = fs.createReadStream('package.json');
this.body = stream; this.body = stream;
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(); var server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json') .expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
var pkg = require('../package'); var pkg = require('../package');
@ -645,7 +645,7 @@ describe('app.respond', function(){
var app = koa(); var app = koa();
app.use(function *(){ 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'); this.body = fs.createReadStream('does not exist');
}); });
@ -703,7 +703,7 @@ describe('app.respond', function(){
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json') .expect('Content-Type', 'application/json; charset=utf-8')
.expect('{"hello":"world"}', done); .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('.jpeg').should.be.false; ctx.is('.jpeg').should.be.false;
ctx.is('text/*', 'application/*').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']); assert('text/html; charset=utf-8' == res.header['content-type']);
res.body = { foo: 'bar' }; 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(){ it('should default to json', function(){
var res = response(); var res = response();
res.body = { foo: 'bar' }; 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 *(){ app.use(function *(){
this.body = { foo: 'bar' }; 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('Content-Length', '15');
this.set('Transfer-Encoding', 'chunked'); this.set('Transfer-Encoding', 'chunked');
this.status = status; this.status = status;
@ -69,7 +69,7 @@ describe('res.status=', function(){
app.use(function *(){ app.use(function *(){
this.status = status; this.status = status;
this.body = { foo: 'bar' }; 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('Content-Length', '15');
this.set('Transfer-Encoding', 'chunked'); this.set('Transfer-Encoding', 'chunked');
}); });

View File

@ -17,7 +17,7 @@ describe('ctx.type=', function(){
var ctx = context(); var ctx = context();
ctx.type = 'json'; ctx.type = 'json';
ctx.type.should.equal('application/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');
}) })
}) })
@ -56,4 +56,4 @@ describe('ctx.type', function(){
ctx.type.should.equal('application/json'); ctx.type.should.equal('application/json');
}) })
}) })
}) })