Add support for CORS / XHR

This is ready to be looked over now.
What's the relevance of setTimeout here?