Http proxy support and code refactoring.

I added a few lines of code to handle the http proxy.
I let you see the changes for inclusion in the main repository.