TODO The code is a mess, basically just a series of hacks refactor fix copyrights etc as most of the code is borrowed from the Debian http and https providers