Browse Source

v 4.1.1.0

Former-commit-id: 2f6b172392cb9955180ac153d260eb4cb4441442
Former-commit-id: 70f6be3cd0a97a828907f2d26f5e49d989e2b773
pull/17/head
James South 12 years ago
parent
commit
269cf6a2ae
  1. 2
      build/NuSpecs/ImageProcessor.Web.nuspec
  2. 2
      build/build.xml
  3. 3
      src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs
  4. 32
      src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs
  5. 4
      src/ImageProcessor.Web/Properties/AssemblyInfo.cs
  6. 130
      src/TestWebsites/MVC/TestImageService.cs
  7. 1
      src/TestWebsites/MVC/Test_Website_MVC.csproj

2
build/NuSpecs/ImageProcessor.Web.nuspec

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata> <metadata>
<id>ImageProcessor.Web</id> <id>ImageProcessor.Web</id>
<version>4.1.0.0</version> <version>4.1.1.0</version>
<title>ImageProcessor.Web</title> <title>ImageProcessor.Web</title>
<authors>James South</authors> <authors>James South</authors>
<owners>James South</owners> <owners>James South</owners>

2
build/build.xml

@ -13,7 +13,7 @@
<project> <project>
<name>ImageProcessor Web</name> <name>ImageProcessor Web</name>
<version>4.1.0.0</version> <version>4.1.1.0</version>
<folder>..\src\ImageProcessor.Web</folder> <folder>..\src\ImageProcessor.Web</folder>
<projfile>ImageProcessor.Web.csproj</projfile> <projfile>ImageProcessor.Web.csproj</projfile>
<outputs> <outputs>

3
src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs

@ -346,8 +346,6 @@ namespace ImageProcessor.Web.Configuration
} }
IImageService imageService = Activator.CreateInstance(type) as IImageService; IImageService imageService = Activator.CreateInstance(type) as IImageService;
if (!string.IsNullOrWhiteSpace(config.Prefix))
{
if (!string.IsNullOrWhiteSpace(config.Prefix)) if (!string.IsNullOrWhiteSpace(config.Prefix))
{ {
if (imageService != null) if (imageService != null)
@ -355,7 +353,6 @@ namespace ImageProcessor.Web.Configuration
imageService.Prefix = config.Prefix; imageService.Prefix = config.Prefix;
} }
} }
}
this.ImageServices.Add(imageService); this.ImageServices.Add(imageService);
} }

32
src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs

@ -280,11 +280,12 @@ namespace ImageProcessor.Web.HttpModules
if (currentService != null) if (currentService != null)
{ {
bool isFileLocal = currentService.IsFileLocalService; bool isFileLocal = currentService.IsFileLocalService;
bool hasMultiParams = request.Url.ToString().Count(f => f == '?') > 1;
string requestPath = string.Empty; string requestPath = string.Empty;
string queryString = string.Empty; string queryString = string.Empty;
string urlParameters = string.Empty; string urlParameters = string.Empty;
if (!isFileLocal) if (hasMultiParams)
{ {
// We need to split the querystring to get the actual values we want. // We need to split the querystring to get the actual values we want.
string urlDecode = HttpUtility.UrlDecode(request.QueryString.ToString()); string urlDecode = HttpUtility.UrlDecode(request.QueryString.ToString());
@ -376,9 +377,11 @@ namespace ImageProcessor.Web.HttpModules
{ {
byte[] imageBuffer; byte[] imageBuffer;
if (!isFileLocal) if (hasMultiParams)
{ {
Uri uri = new Uri(requestPath + "?" + urlParameters); Uri uri = string.IsNullOrWhiteSpace(urlParameters)
? new Uri(requestPath, UriKind.RelativeOrAbsolute)
: new Uri(requestPath + "?" + urlParameters, UriKind.RelativeOrAbsolute);
imageBuffer = await currentService.GetImage(uri); imageBuffer = await currentService.GetImage(uri);
} }
else else
@ -435,13 +438,22 @@ namespace ImageProcessor.Web.HttpModules
if (isFileLocal) if (isFileLocal)
{ {
// Set the headers and quit. // Set the headers and quit.
this.SetHeaders(context, (string)context.Items[CachedResponseTypeKey], new List<string> { requestPath, cachedPath }); // Some services might only provide filename so we can't monitor for the browser.
return; this.SetHeaders(
context,
(string)context.Items[CachedResponseTypeKey],
Path.GetFileName(requestPath) == requestPath ? new List<string> { cachedPath } : new List<string> { requestPath, cachedPath });
} }
else
{
this.SetHeaders(context, (string)context.Items[CachedResponseTypeKey], new List<string> { cachedPath }); this.SetHeaders(context, (string)context.Items[CachedResponseTypeKey], new List<string> { cachedPath });
} }
// Complete the requests but don't abort the thread.
context.ApplicationInstance.CompleteRequest();
return;
}
// The cached file is valid so just rewrite the path. // The cached file is valid so just rewrite the path.
context.RewritePath(virtualCachedPath, false); context.RewritePath(virtualCachedPath, false);
} }
@ -450,11 +462,6 @@ namespace ImageProcessor.Web.HttpModules
throw new HttpException(403, "Access denied"); throw new HttpException(403, "Access denied");
} }
} }
else if (!isFileLocal)
{
// Just re-point to the external url.
HttpContext.Current.Response.Redirect(requestPath);
}
} }
} }
@ -496,6 +503,9 @@ namespace ImageProcessor.Web.HttpModules
cache.SetExpires(DateTime.Now.ToUniversalTime().AddDays(maxDays)); cache.SetExpires(DateTime.Now.ToUniversalTime().AddDays(maxDays));
cache.SetMaxAge(new TimeSpan(maxDays, 0, 0, 0)); cache.SetMaxAge(new TimeSpan(maxDays, 0, 0, 0));
cache.SetRevalidation(HttpCacheRevalidation.AllCaches); cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
context.Items[CachedResponseTypeKey] = null;
context.Items[CachedResponseFileDependency] = null;
} }
/// <summary> /// <summary>

4
src/ImageProcessor.Web/Properties/AssemblyInfo.cs

@ -40,5 +40,5 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("4.1.0.0")] [assembly: AssemblyVersion("4.1.1.0")]
[assembly: AssemblyFileVersion("4.1.0.0")] [assembly: AssemblyFileVersion("4.1.1.0")]

130
src/TestWebsites/MVC/TestImageService.cs

@ -0,0 +1,130 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TestImageService.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// The test image service.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Test_Website_NET45
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Web;
using System.Web.Hosting;
using ImageProcessor.Web.Services;
/// <summary>
/// The test image service.
/// </summary>
public class TestImageService : IImageService
{
/// <summary>
/// The prefix for the given implementation.
/// </summary>
private string prefix = "testprovider.axd";
/// <summary>
/// Gets or sets the prefix for the given implementation.
/// <remarks>
/// This value is used as a prefix for any image requests that should use this service.
/// </remarks>
/// </summary>
public string Prefix
{
get
{
return this.prefix;
}
set
{
this.prefix = value;
}
}
/// <summary>
/// Gets a value indicating whether the image service requests files from
/// the locally based file system.
/// </summary>
public bool IsFileLocalService
{
get
{
return true;
}
}
/// <summary>
/// Gets or sets any additional settings required by the service.
/// </summary>
public Dictionary<string, string> Settings { get; set; }
/// <summary>
/// Gets or sets the white list of <see cref="System.Uri"/>.
/// </summary>
public Uri[] WhiteList { get; set; }
/// <summary>
/// Gets a value indicating whether the current request passes sanitizing rules.
/// </summary>
/// <param name="path">
/// The image path.
/// </param>
/// <returns>
/// <c>True</c> if the request is valid; otherwise, <c>False</c>.
/// </returns>
public bool IsValidRequest(string path)
{
return true;
}
/// <summary>
/// Gets the image using the given identifier.
/// </summary>
/// <param name="id">
/// The value identifying the image to fetch.
/// </param>
/// <returns>
/// The <see cref="System.Byte"/> array containing the image data.
/// </returns>
public async Task<byte[]> GetImage(object id)
{
const string AppData = "~/App_Data/images";
string imageRoot = HostingEnvironment.MapPath(AppData);
if (imageRoot == null)
{
throw new HttpException(404, "No root path found to serve " + id);
}
// In this instance we are just processing a set path.
// If you are using the querystring params as a means of identifying the correct image
// then you can do something with it here.
string path = Path.Combine(imageRoot, id.ToString().Split(new[] { '&', '?' })[0]);
byte[] buffer;
// Check to see if the file exists.
// ReSharper disable once AssignNullToNotNullAttribute
FileInfo fileInfo = new FileInfo(path);
if (!fileInfo.Exists)
{
throw new HttpException(404, "Nothing found at " + id);
}
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true))
{
buffer = new byte[file.Length];
await file.ReadAsync(buffer, 0, (int)file.Length);
}
return buffer;
}
}
}

1
src/TestWebsites/MVC/Test_Website_MVC.csproj

@ -109,6 +109,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="TestImageService.cs" />
<Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs"> <Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon> <DependentUpon>Global.asax</DependentUpon>

Loading…
Cancel
Save