Set content length header when necessary

Fixes #227.