Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Check StorageException response code. Fix #809
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Jul 21, 2020
1 parent d6e748f commit a369ac9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $imageprocessorWebConfig = @{

$imageProcessorWebPluginsAzureBlobCache = @{
name = "ImageProcessor.Web.Plugins.AzureBlobCache"
version = "1.7.0"
version = "1.7.1"
folder = Join-Path $buildPath "src\ImageProcessor.Web.Plugins.AzureBlobCache"
output = Join-Path $binPath "ImageProcessor.Web.Plugins.AzureBlobCache\lib\net452"
csproj = "ImageProcessor.Web.Plugins.AzureBlobCache.csproj"
Expand Down
30 changes: 19 additions & 11 deletions src/ImageProcessor.Web.Plugins.AzureBlobCache/AzureBlobCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace ImageProcessor.Web.Plugins.AzureBlobCache
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
Expand Down Expand Up @@ -357,18 +358,25 @@ public override void RewritePath(HttpContext context)
catch (StorageException ex)
{
// A 304 is not a true error, we still need to feed back.
var webException = ex.InnerException as WebException;
if (!(webException is null))
if (ex.RequestInformation?.HttpStatusCode == (int)HttpStatusCode.NotModified)
{
if (webException.Response != null && (((HttpWebResponse)webException.Response).StatusCode == HttpStatusCode.NotModified))
{
is304 = true;
}
else
{
ImageProcessorBootstrapper.Instance.Logger.Log<AzureBlobCache>("Unable to stream cached path: " + this.cachedRewritePath);
return;
}
is304 = true;
}
else if (ex.InnerException is WebException webException
&& webException.Response is HttpWebResponse httpWebResponse
&& httpWebResponse.StatusCode == HttpStatusCode.NotModified)
{
is304 = true;
}
else
{
var sb = new StringBuilder();
sb.AppendFormat("Unable to stream cached path: {0}", this.cachedRewritePath);
sb.AppendLine();
sb.AppendFormat("Exception: {0}", ex.ToString());

ImageProcessorBootstrapper.Instance.Logger.Log<AzureBlobCache>(sb.ToString());
return;
}
}

Expand Down

0 comments on commit a369ac9

Please sign in to comment.