Flush headers before potentially blocking

 Replaces #533