Skip to content

Commit 42cd9e2

Browse files
committed
Adding a null check on HttpContext.Current to allow unit tests to execute - I think really we need a HttpContext Mock (http://stackoverflow.com/questions/9624242/setting-httpcontext-current-session-in-a-unit-test)
1 parent 37daa28 commit 42cd9e2

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/UmbracoFileSystemProviders.Azure/FileSystemVirtualFile.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,19 @@ public override bool IsDirectory
6767
public override Stream Open()
6868
{
6969
// Set the response headers here. It's a bit hacky.
70-
HttpCachePolicy cache = HttpContext.Current.Response.Cache;
71-
cache.SetCacheability(HttpCacheability.Public);
72-
cache.VaryByHeaders["Accept-Encoding"] = true;
70+
if (HttpContext.Current != null)
71+
{
72+
HttpCachePolicy cache = HttpContext.Current.Response.Cache;
73+
cache.SetCacheability(HttpCacheability.Public);
74+
cache.VaryByHeaders["Accept-Encoding"] = true;
7375

74-
IFileSystem azureBlobFileSystem = FileSystemProviderManager.Current.GetUnderlyingFileSystemProvider("media");
75-
int maxDays = ((AzureBlobFileSystem)azureBlobFileSystem).FileSystem.MaxDays;
76+
IFileSystem azureBlobFileSystem = FileSystemProviderManager.Current.GetUnderlyingFileSystemProvider("media");
77+
int maxDays = ((AzureBlobFileSystem)azureBlobFileSystem).FileSystem.MaxDays;
7678

77-
cache.SetExpires(DateTime.Now.ToUniversalTime().AddDays(maxDays));
78-
cache.SetMaxAge(new TimeSpan(maxDays, 0, 0, 0));
79-
cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
79+
cache.SetExpires(DateTime.Now.ToUniversalTime().AddDays(maxDays));
80+
cache.SetMaxAge(new TimeSpan(maxDays, 0, 0, 0));
81+
cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
82+
}
8083

8184
return this.stream();
8285
}

0 commit comments

Comments
 (0)