Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
exports.ContentLengthMiddleware = function (app) {
return function (request) {
return Q.when(app(request), function (response) {
var stream = new ByteIO();
var write = function (line) {
stream.write(line.toByteString("utf-8"));
};
return Q.when(response.body.forEach(write), function () {
var content = stream.read();
response.headers['Content-length'] = content;
response.body = [content];
return response;
});
});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment