Skip to content

Instantly share code, notes, and snippets.

@robertklep
Created May 4, 2013 06:55
Show Gist options
  • Save robertklep/5516529 to your computer and use it in GitHub Desktop.
Save robertklep/5516529 to your computer and use it in GitHub Desktop.
Simple Express/Connect middleware that dumps a stack trace to console when response-headers are written. Useful to debug "Can't set headers after they are sent" issues.
// include this middleware before any middleware/routes that is suspected of triggering the error
app.use(function(req, res, next) {
res.on('header', function() {
console.trace('HEADERS GOING TO BE WRITTEN');
});
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment