BUG: in some cases the headers would be sent after the response endedt