Esempio n. 1
0
        /// <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 FetchWithCorsAsync(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 is "about:blank")
            {
                return(loader.FetchFromSameOriginAsync(url, cors));
            }
            else if (setting == CorsSetting.Anonymous || setting == CorsSetting.UseCredentials)
            {
                return(loader.FetchFromDifferentOriginAsync(cors));
            }
            else if (setting == CorsSetting.None)
            {
                return(loader.FetchWithoutCorsAsync(request, cors.Behavior));
            }

            throw new DomException(DomError.Network);
        }