diff --git a/lib/application.js b/lib/application.js index b26f354..c59ab9d 100644 --- a/lib/application.js +++ b/lib/application.js @@ -9,7 +9,7 @@ var isJSON = require('koa-is-json'); var response = require('./response'); var context = require('./context'); var request = require('./request'); -var finished = require('finished'); +var onFinished = require('on-finished'); var Cookies = require('cookies'); var accepts = require('accepts'); var status = require('statuses'); @@ -121,7 +121,7 @@ app.callback = function(){ return function(req, res){ res.statusCode = 404; var ctx = self.createContext(req, res); - finished(ctx, ctx.onerror); + onFinished(res, ctx.onerror); fn.call(ctx, ctx.onerror); } }; diff --git a/lib/response.js b/lib/response.js index f4dc8d6..2d96c22 100644 --- a/lib/response.js +++ b/lib/response.js @@ -7,7 +7,7 @@ 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 onFinish = require('on-finished'); var typeis = require('type-is').is; var status = require('statuses'); var destroy = require('destroy'); @@ -127,7 +127,7 @@ module.exports = { // stream if ('function' == typeof val.pipe) { - onfinish(this, destroy.bind(null, val)); + onFinish(this.res, destroy.bind(null, val)); ensureErrorHandler(val, this.ctx.onerror); // overwriting diff --git a/package.json b/package.json index 3cf4d88..d4cb2fc 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "type-is": "~1.3.1", "mime-types": "~1.0.0", "media-typer": "~0.2.0", - "finished": "~1.2.0", + "on-finished": "~2.0.0", "co": "~3.1.0", "debug": "*", "fresh": "~0.2.1", diff --git a/test/context.js b/test/context.js index 176b6f1..bdf163a 100644 --- a/test/context.js +++ b/test/context.js @@ -1,13 +1,14 @@ -var ReadableStream = require('stream').Readable; +var Stream = require('stream'); var context = require('../lib/context'); var request = require('../lib/request'); var response = require('../lib/response'); var koa = require('..'); exports = module.exports = function(req, res){ - req = req || { headers: {}, socket: new ReadableStream() }; - res = res || { _headers: {} }; + var socket = new Stream.Duplex(); + req = req || { headers: {}, socket: socket, __proto__: Stream.Readable.prototype }; + res = res || { _headers: {}, socket: socket, __proto__: Stream.Writable.prototype }; res.getHeader = function(k){ return res._headers[k.toLowerCase()] }; res.setHeader = function(k, v){ res._headers[k.toLowerCase()] = v }; res.removeHeader = function(k, v){ delete res._headers[k.toLowerCase()] }; diff --git a/test/context/writable.js b/test/context/writable.js deleted file mode 100644 index fd18ee0..0000000 --- a/test/context/writable.js +++ /dev/null @@ -1,10 +0,0 @@ - -var context = require('../context'); - -describe('ctx.writable', function(){ - it('should not crash when the socket does not exist', function(){ - var ctx = context(); - ctx.socket = null; - ctx.writable.should.equal(false); - }) -}) \ No newline at end of file