Skip to content

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

@DominicFarrington

Description

@DominicFarrington

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions