private static IDownload FetchFromDifferentOrigin(this IResourceLoader loader, CorsRequest cors) { var request = cors.Request; request.IsCredentialOmitted = cors.IsAnonymous(); var download = loader.DownloadAsync(request); return(download.Wrap(response => { if (response?.StatusCode != HttpStatusCode.OK) { response?.Dispose(); throw new DomException(DomError.Network); } return cors.CheckIntegrity(download); })); }
private static IDownload FetchFromSameOrigin(this IResourceLoader loader, Url url, CorsRequest cors) { var request = cors.Request; var download = loader.DownloadAsync(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.FetchWithCors(cors.RedirectTo(url)) : loader.FetchFromSameOrigin(url, cors); } return cors.CheckIntegrity(download); })); }