Add Cross-Origin Resource Sharing (CORS) support.

This still misses documentation, but I want to have a review on the code first.

@rfk r?