Skip to content

Commit 2fd9a31

Browse files
Ensure the current context is sent to events.
1 parent ca4dca7 commit 2fd9a31

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

src/ImageProcessor.Web/Helpers/PostProcessingEventArgs.cs

+6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111
namespace ImageProcessor.Web.Helpers
1212
{
1313
using System;
14+
using System.Web;
1415

1516
/// <summary>
1617
/// The post processing event arguments.
1718
/// </summary>
1819
public class PostProcessingEventArgs : EventArgs
1920
{
21+
/// <summary>
22+
/// Gets or sets the current request context.
23+
/// </summary>
24+
public HttpContext Context { get; set; }
25+
2026
/// <summary>
2127
/// Gets or sets the cached image path.
2228
/// </summary>

src/ImageProcessor.Web/Helpers/ProcessQueryStringEventArgs.cs

+6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111
namespace ImageProcessor.Web.Helpers
1212
{
1313
using System;
14+
using System.Web;
1415

1516
/// <summary>
1617
/// The process querystring event arguments.
1718
/// </summary>
1819
public class ProcessQueryStringEventArgs : EventArgs
1920
{
21+
/// <summary>
22+
/// Gets or sets the current request context.
23+
/// </summary>
24+
public HttpContext Context { get; set; }
25+
2026
/// <summary>
2127
/// Gets or sets the querystring.
2228
/// </summary>

src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs

+24-15
Original file line numberDiff line numberDiff line change
@@ -252,25 +252,25 @@ public static void AddCorsRequestHeaders(HttpContext context)
252252
/// <summary>
253253
/// Initializes a module and prepares it to handle requests.
254254
/// </summary>
255-
/// <param name="context">
255+
/// <param name="application">
256256
/// An <see cref="T:System.Web.HttpApplication"/> that provides
257257
/// access to the methods, properties, and events common to all
258258
/// application objects within an ASP.NET application
259259
/// </param>
260-
public void Init(HttpApplication context)
260+
public void Init(HttpApplication application)
261261
{
262262
if (preserveExifMetaData == null)
263263
{
264264
preserveExifMetaData = ImageProcessorConfiguration.Instance.PreserveExifMetaData;
265265
}
266266

267267
EventHandlerTaskAsyncHelper postAuthorizeHelper = new EventHandlerTaskAsyncHelper(this.PostAuthorizeRequest);
268-
context.AddOnPostAuthorizeRequestAsync(postAuthorizeHelper.BeginEventHandler, postAuthorizeHelper.EndEventHandler);
268+
application.AddOnPostAuthorizeRequestAsync(postAuthorizeHelper.BeginEventHandler, postAuthorizeHelper.EndEventHandler);
269269

270-
context.PostReleaseRequestState += this.PostReleaseRequestState;
270+
application.PostReleaseRequestState += this.PostReleaseRequestState;
271271

272272
EventHandlerTaskAsyncHelper postProcessHelper = new EventHandlerTaskAsyncHelper(this.PostProcessImage);
273-
context.AddOnEndRequestAsync(postProcessHelper.BeginEventHandler, postProcessHelper.EndEventHandler);
273+
application.AddOnEndRequestAsync(postProcessHelper.BeginEventHandler, postProcessHelper.EndEventHandler);
274274
}
275275

276276
/// <summary>
@@ -360,7 +360,14 @@ private async Task PostProcessImage(object sender, EventArgs e)
360360
if (handler != null)
361361
{
362362
context.Items[CachedPathKey] = null;
363-
await Task.Run(() => handler(this, new PostProcessingEventArgs { CachedImagePath = cachedPath }));
363+
await Task.Run(
364+
() => handler(
365+
this,
366+
new PostProcessingEventArgs
367+
{
368+
Context = context,
369+
CachedImagePath = cachedPath
370+
}));
364371
}
365372
}
366373

@@ -483,7 +490,7 @@ private async Task ProcessImageAsync(HttpContext context)
483490
queryString = this.ReplacePresetsInQueryString(queryString);
484491

485492
// Execute the handler which can change the querystring
486-
queryString = this.CheckQuerystringHandler(queryString, request.Unvalidated.RawUrl);
493+
queryString = this.CheckQuerystringHandler(context, queryString, request.Unvalidated.RawUrl);
487494

488495
if (string.IsNullOrWhiteSpace(requestPath))
489496
{
@@ -634,22 +641,24 @@ private string ReplacePresetsInQueryString(string queryString)
634641
/// <summary>
635642
/// Checks if there is a handler that changes the querystring and executes that handler.
636643
/// </summary>
637-
/// <param name="queryString">
638-
/// The query string.
639-
/// </param>
640-
/// <param name="rawUrl">
641-
/// The raw request url.
642-
/// </param>
644+
/// <param name="context">The current request context.</param>
645+
/// <param name="queryString">The query string.</param>
646+
/// <param name="rawUrl">The raw request url.</param>
643647
/// <returns>
644648
/// The <see cref="string"/> containing the updated querystring.
645649
/// </returns>
646-
private string CheckQuerystringHandler(string queryString, string rawUrl)
650+
private string CheckQuerystringHandler(HttpContext context, string queryString, string rawUrl)
647651
{
648652
// Fire the process querystring event.
649653
ProcessQuerystringEventHandler handler = OnProcessQuerystring;
650654
if (handler != null)
651655
{
652-
ProcessQueryStringEventArgs args = new ProcessQueryStringEventArgs { Querystring = queryString ?? string.Empty, RawUrl = rawUrl ?? string.Empty };
656+
ProcessQueryStringEventArgs args = new ProcessQueryStringEventArgs
657+
{
658+
Context = context,
659+
Querystring = queryString ?? string.Empty,
660+
RawUrl = rawUrl ?? string.Empty
661+
};
653662
queryString = handler(this, args);
654663
}
655664

0 commit comments

Comments
 (0)