only write headers before sending