/// <summary> /// This is where we hijack the resizing process, interrupt it, and send /// back the JSON data we created. /// </summary> /// <param name="sender"></param> /// <param name="context"></param> /// <param name="e"></param> void Pipeline_PreHandleImage(System.Web.IHttpModule sender, System.Web.HttpContext context, Caching.IResponseArgs e) { if (!this.IsDiagnosticRequest(e.RewrittenQuerystring)) { return; } AlternateResponseException.InjectExceptionHandler(e as ImageResizer.Caching.ResponseArgs); }
/* http://developer.yahoo.com/performance/rules.html * http://24x7aspnet.blogspot.com/2009/06/using-cache-methods-httpcacheability-in.html * * Redirects should have caching headers. * Expires: is good * Remove ETags, bad server implementation */ void Pipeline_PreHandleImage(System.Web.IHttpModule sender, System.Web.HttpContext context, Caching.IResponseArgs e) { int mins = c.get("clientcache.minutes", -1); //Set the expires value if present if (mins > 0) { e.ResponseHeaders.Expires = DateTime.UtcNow.AddMinutes(mins); // Hieu Le: Apr-16-2014: // Set MaxAge e.ResponseHeaders.MaxAge = new TimeSpan(0, 0, mins, 0); } //NDJ Jan-16-2013. The last modified date sent in the headers should NOT match the source modified date when using DiskCaching. //Setting this will prevent 304s from being sent properly. // (Moved to NoCache) //Authenticated requests only allow caching on the client. //Anonymous requests get caching on the server, proxy and client if (context.Request.IsAuthenticated) { e.ResponseHeaders.CacheControl = System.Web.HttpCacheability.Private; } else { e.ResponseHeaders.CacheControl = System.Web.HttpCacheability.Public; } }
/// <summary> /// This is where we hijack the resizing process, interrupt it, and send back the json data we created. /// </summary> /// <param name="sender"></param> /// <param name="context"></param> /// <param name="e"></param> void Pipeline_PreHandleImage(System.Web.IHttpModule sender, System.Web.HttpContext context, Caching.IResponseArgs e) { bool detect = NameValueCollectionExtensions.Get(e.RewrittenQuerystring, "f.detect", false); bool getlayout = NameValueCollectionExtensions.Get(e.RewrittenQuerystring, "f.getlayout", false); if (!detect && !getlayout) { return; } DetectionResponse <Face> .InjectExceptionHandler(e as ResponseArgs); }
private static void OnPreHandleImage(IHttpModule sender, HttpContext context, Caching.IResponseArgs e) { ServiceLocator.Current.GetInstance <ICacheHelper>().SetCacheHeaders(context, GetLastModifiedFromRequestKey(e.RequestKey), "ImageResizer"); }
/// <summary> /// This is where we hijack the resizing process, interrupt it, and send back the json data we created. /// </summary> /// <param name="sender"></param> /// <param name="context"></param> /// <param name="e"></param> void Pipeline_PreHandleImage(System.Web.IHttpModule sender, System.Web.HttpContext context, Caching.IResponseArgs e) { if (NameValueCollectionExtensions.Get(e.RewrittenQuerystring, "r.detecteyes", false) || NameValueCollectionExtensions.Get(e.RewrittenQuerystring, "r.getlayout", false)) { DetectionResponse <ObjRect> .InjectExceptionHandler(e as ResponseArgs); } }
void Pipeline_PreHandleImage(System.Web.IHttpModule sender, System.Web.HttpContext context, Caching.IResponseArgs e) { string info = e.RewrittenQuerystring["getinfo"]; if (string.IsNullOrEmpty(info)) { return; } ResponseArgs ra = e as ResponseArgs; e.ResponseHeaders.ContentType = "application/json; charset=utf-8"; NameValueCollection d = new NameValueCollection(); ra.ResizeImageToStream = new ResizeImageDelegate(delegate(Stream s) { try { using (Stream src = ra.GetSourceImage()) { bool attemptFastMode = src.CanSeek; long orig = attemptFastMode ? src.Position : 0; bool trySlowMode = !attemptFastMode; if (attemptFastMode) { try { using (Image i = System.Drawing.Image.FromStream(src, false, false)) { d["width"] = i.Width.ToString(); d["height"] = i.Height.ToString(); } } catch { trySlowMode = true; } } if (trySlowMode) { if (attemptFastMode) { src.Seek(orig, SeekOrigin.Begin); } using (Bitmap b = c.CurrentImageBuilder.LoadImage(src, new ResizeSettings(ra.RewrittenQuerystring))){ d["width"] = b.Width.ToString(); d["height"] = b.Height.ToString(); } } SimpleJson(s, d, e.RewrittenQuerystring["jsonp"]); } } catch (FileNotFoundException) { d["result"] = "404"; SimpleJson(s, d, e.RewrittenQuerystring["jsonp"]); } }); }
/// <summary> /// This is where we hijack the resizing process, interrupt it, and send back the json data we created. /// </summary> /// <param name="sender"></param> /// <param name="context"></param> /// <param name="e"></param> void Pipeline_PreHandleImage(System.Web.IHttpModule sender, System.Web.HttpContext context, Caching.IResponseArgs e) { if (e.RewrittenQuerystring.Get("resizer.debug", DebugType.None) != DebugType.None) { InjectRequestMod(e as ResponseArgs); if (!Diagnostic.AllowResponse(context, this.c)) { throw GetResponseException(Diagnostic.DisabledNotice(c)); } } }
static void Pipeline_PreHandleImage(System.Web.IHttpModule sender, System.Web.HttpContext context, Caching.IResponseArgs e) { if (!Config.Current.Plugins.Has <Trial>()) { new Trial().Install(Config.Current); } }