Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Created February 3, 2010 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kriskowal/293510 to your computer and use it in GitHub Desktop.
Save kriskowal/293510 to your computer and use it in GitHub Desktop.
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