Use the mainResponse for headersSent check

As this is the response we want to gate writing on