Exemple #1
0
        private static IDownload FetchFromDifferentOriginAsync(this IResourceLoader loader, CorsRequest cors)
        {
            var request = cors.Request;

            request.IsCredentialOmitted = cors.IsAnonymous();
            var download = loader.FetchAsync(request);

            return(download.Wrap(response =>
            {
                if (response?.StatusCode != HttpStatusCode.OK)
                {
                    response?.Dispose();
                    throw new DomException(DomError.Network);
                }

                return cors.CheckIntegrity(download);
            }));
        }
Exemple #2
0
        private static IDownload FetchFromSameOriginAsync(this IResourceLoader loader, Url url, CorsRequest cors)
        {
            var request  = cors.Request;
            var download = loader.FetchAsync(new ResourceRequest(request.Source, url)
            {
                Origin = request.Origin,
                IsManualRedirectDesired = true
            });

            return(download.Wrap(response =>
            {
                if (response.IsRedirected())
                {
                    url.Href = response.Headers.GetOrDefault(HeaderNames.Location, url.Href);

                    return request.Origin.Is(url.Origin) ?
                    loader.FetchWithCorsAsync(cors.RedirectTo(url)) :
                    loader.FetchFromSameOriginAsync(url, cors);
                }

                return cors.CheckIntegrity(download);
            }));
        }