Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSystemVirtualFile doesn't set etag and last modified from Azure on cache header #170

Open
DominicFarrington opened this issue Aug 21, 2020 · 0 comments

Comments

@DominicFarrington
Copy link

FileSystemVirtualFile has the following code:

        /// <summary>
        /// When overridden in a derived class, returns a read-only stream to the virtual resource.
        /// </summary>
        /// <returns>
        /// A read-only stream to the virtual file.
        /// </returns>
        public override Stream Open()
        {
            // Set the response headers here. It's a bit hacky.
            if (HttpContext.Current != null)
            {
                HttpCachePolicy cache = HttpContext.Current.Response.Cache;
                cache.SetCacheability(HttpCacheability.Public);
                cache.VaryByHeaders["Accept-Encoding"] = true;

                // Add Accept-Ranges header to fix videos not playing on Safari
                HttpContext.Current.Response.AppendHeader("Accept-Ranges", "bytes");

                IFileSystem azureBlobFileSystem = FileSystemProviderManager.Current.GetUnderlyingFileSystemProvider("media");
                int maxDays = ((AzureBlobFileSystem)azureBlobFileSystem).FileSystem.MaxDays;

                cache.SetExpires(DateTime.Now.ToUniversalTime().AddDays(maxDays));
                cache.SetMaxAge(new TimeSpan(maxDays, 0, 0, 0));
                cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
            }

            return this.stream();
        }

This doesn't call

cache.SetETag(...);
cache.SetLastModified(..);

Last modified appears to already be available in AzureBlobFileSystem could be an easy upgrade. ETag would be a bonus!

Would help with CDN hosting of media files. Encountered the issue on Umbraco 7.15.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant