compute and set content-length just before sending content

rather than in various places