move 401 page output writing to write_responses