Check res.headersSent before calling res.setHeader() in bail()

I noticed sometimes `bail()` would be called after headers had already been written on the response. In this case, instead of writing the error back on the response, it throws and kills the server process. 

This fix just doesn't set `text/plain` if headers have already been written, so the error is written to the request and the server can serve subsequent requests.