bugfix writeAllHeaders incorrect total length calculation