Borrowed code directly from Network.HTTP - Removed haskell-http as dep