fixed sending error twice when another middleware already sent the headers
Merge pull request #1264 from jarnoux/master

better output handler response header check