koa-spdy-push
Advanced tools
Comparing version 0.1.6 to 0.1.7
26
index.js
@@ -15,3 +15,5 @@ | ||
return function push(context, options) { | ||
return function push(context, options, done) { | ||
done = done || noop | ||
// koa properties | ||
@@ -44,2 +46,3 @@ var res = context.res | ||
// regular push stream handling | ||
var stream = res.push(path, headers, priority) | ||
@@ -51,2 +54,12 @@ stream.on('acknowledge', acknowledge) | ||
// handle the deferred thunk | ||
stream.on('finish', finish) | ||
stream.on('error', finish) | ||
stream.on('close', finish) | ||
socket.on('close', finish) | ||
return function (fn) { | ||
done = fn | ||
} | ||
function acknowledge() { | ||
@@ -111,2 +124,11 @@ cleanup() | ||
} | ||
function finish(err) { | ||
done(filterError(err), stream) | ||
stream.removeListener('finish', finish) | ||
stream.removeListener('error', finish) | ||
stream.removeListener('close', finish) | ||
socket.removeListener('close', finish) | ||
} | ||
} | ||
@@ -122,1 +144,3 @@ } | ||
} | ||
function noop() {} |
{ | ||
"name": "koa-spdy-push", | ||
"description": "SPDY Push helper for Koa", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Jonathan Ong", |
@@ -123,6 +123,2 @@ | ||
describe('Files without Content-Length', function () { | ||
// stupid `res.socket = null` is being set on next tick | ||
}) | ||
describe('RST_STREAM', function () { | ||
@@ -191,2 +187,30 @@ it('should not leak file descriptors', co(function* () { | ||
describe('yield push', function () { | ||
it('should wait until the stream is finished writing', co(function* () { | ||
yield listen(koa().use(function* () { | ||
this.status = 204 | ||
var stream = yield push({ | ||
threshold: 1 | ||
})(this, { | ||
path: '/', | ||
headers: { | ||
'content-encoding': 'gzip', | ||
'content-type': 'text/plain' | ||
}, | ||
body: yield zlib.gzip('lol') | ||
}) | ||
stream.writable.should.be.false | ||
})) | ||
var res = yield pull | ||
res.should.have.header('Content-Encoding', 'gzip') | ||
res.should.have.header('Content-Type', 'text/plain') | ||
var buffer = yield get(res) | ||
buffer.toString('utf8').should.equal('lol') | ||
})) | ||
}) | ||
function listen(app) { | ||
@@ -193,0 +217,0 @@ // app.outputErrors = true |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12986
325