diff --git a/lib/response.js b/lib/response.js index 39cdaef..5ef6708 100644 --- a/lib/response.js +++ b/lib/response.js @@ -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'); diff --git a/package.json b/package.json index f7a826d..7d1991d 100644 --- a/package.json +++ b/package.json @@ -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": "*", diff --git a/test/application.js b/test/application.js index 8fbf9b8..5215d9a 100644 --- a/test/application.js +++ b/test/application.js @@ -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); }) }) diff --git a/test/request/is.js b/test/request/is.js index 415d9e5..9d83e3b 100644 --- a/test/request/is.js +++ b/test/request/is.js @@ -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; }) }) diff --git a/test/response/body.js b/test/response/body.js index 55358e0..a093436 100644 --- a/test/response/body.js +++ b/test/response/body.js @@ -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']); }) }) }) \ No newline at end of file diff --git a/test/response/status.js b/test/response/status.js index 2af64bf..f7f4bf8 100644 --- a/test/response/status.js +++ b/test/response/status.js @@ -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'); }); diff --git a/test/response/type.js b/test/response/type.js index b5c8c48..1897d87 100644 --- a/test/response/type.js +++ b/test/response/type.js @@ -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'); }) }) @@ -56,4 +56,4 @@ describe('ctx.type', function(){ ctx.type.should.equal('application/json'); }) }) -}) \ No newline at end of file +})