Added basic functionality. Still missing one piece.
I have no idea why it doesn't work, but it's a starting point. Going to rewrite it using http.request next.