Fixed memory management for POSTed JSON and added a computed Content-Length header