Handle connection close of POST/PUT request correctly so that server can...

... close a connection after sending the response without reading the whole request body.
If we have to cast to int anyway, shouldn't `HttpRequest.contentLength` also be int?