Handle the chunked http requests.

The fix is based on Daniel Graña's commit which has not been merged into mainline.
It should fix issues 252 and 367.
Merge pull request #377 from pooya/shayan/upstream_http_chunked

Handle the chunked http requests.