/// <summary> /// Performs a potentially CORS-enabled fetch from the given URI by /// using an asynchronous GET request. For more information see: /// http://www.w3.org/TR/html5/infrastructure.html#potentially-cors-enabled-fetch /// </summary> /// <param name="loader">The resource loader to use.</param> /// <param name="cors">The CORS request to issue.</param> /// <returns> /// The active download. /// </returns> public static IDownload FetchWithCors(this IResourceLoader loader, CorsRequest cors) { var request = cors.Request; var setting = cors.Setting; var url = request.Target; if (request.Origin == url.Origin || url.Scheme == ProtocolNames.Data || url.Href == "about:blank") { return(loader.FetchFromSameOrigin(url, cors)); } else if (setting == CorsSetting.Anonymous || setting == CorsSetting.UseCredentials) { return(loader.FetchFromDifferentOrigin(cors)); } else if (setting == CorsSetting.None) { return(loader.FetchWithoutCors(request, cors.Behavior)); } throw new DomException(DomError.Network); }