Fix restore res.write to original function before call to res.end