Refactor download to util and added retry logic in it.

Using request-replay with streams did not work well because piped data would be concatenated on retry and so on.

This fixes #704 #699
Also improves #700 behaviour.