Fixed bug where the wrong headers were written if body is empty (not written)