ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Protected Member Functions | Protected Attributes | Properties | Events | List of all members
ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin Class Reference
Inheritance diagram for ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin:
Collaboration graph
[legend]

Public Member Functions

Configuration.Xml.Node RedactFrom (Node resizer)
 
IPlugin Install (Configuration.Config c)
 
bool Uninstall (Configuration.Config c)
 
string CreateSignedUrl (string remoteUrl, NameValueCollection settings)
 Generates a signed domain-relative URL in the form "/app/remote.jpg.ashx?width=200&urlb64=aHnSh3haSh...&hmac=913f3KJGK3hj" More...
 
string CreateSignedUrl (string remoteUrl, string settings)
 
string CreateSignedUrlWithKey (string remoteUrl, string settings, string key)
 
string SignData (string data)
 
string SignDataWithKey (string data, string key)
 
RemoteRequestEventArgs ParseRequest (string virtualPath, NameValueCollection query)
 Parses the specified path and querystring. Verifies the hmac signature for querystring specified paths, parses the human-friendly syntax for that syntax. Verifies the URL is properly formed. Returns an object containing the remote URL, querystring remainder, and a flag stating whether the request was signed or not. Incorrectly signed requests immediately throw an exception. More...
 
bool IsRemotePath (string virtualPath)
 
bool FileExists (string virtualPath, System.Collections.Specialized.NameValueCollection queryString)
 
IVirtualFile GetFile (string virtualPath, System.Collections.Specialized.NameValueCollection queryString)
 
IEnumerable< IIssueGetIssues ()
 
Stream GetUriStream (Uri uri, int maxRedirects=-1)
 Returns a stream of the HTTP response to the specified URL with a 15 second timeout. Throws a FileNotFoundException instead of a WebException for 404 errors. Can throw a variety of exceptions: ProtocolViolationException, WebException, FileNotFoundException, SecurityException, NotSupportedException?, and InvalidOperationException?. More...
 
- Public Member Functions inherited from ImageResizer.Resizing.AbstractImageProcessor
 AbstractImageProcessor ()
 Creates a new AbstractImageProcessor with no extensions More...
 
 AbstractImageProcessor (IEnumerable< BuilderExtension > extensions)
 Creates a new AbstractImageProcessor which will run the specified extensions with each method call. More...
 
virtual Bitmap DecodeStreamFailed (Stream s, ResizeSettings settings, string optionalPath)
 Extensions are executed until one extension returns a non-null value. This is taken to mean that the error has been resolved. Extensions should not throw an exception unless they wish to cause subsequent extensions to not execute. If extensions throw an ArgumentException or ExternalException, it will be wrapped in an ImageCorruptedException instance. If the Bitmap class is used for decoding, read gdi-bugs.txt and make sure you set b.Tag to new BitmapTag(optionalPath,stream); More...
 
virtual Bitmap DecodeStream (Stream s, ResizeSettings settings, string optionalPath)
 Extend this to support alternate image source formats. If the Bitmap class is used for decoding, read gdi-bugs.txt and make sure you set b.Tag to new BitmapTag(optionalPath,stream); More...
 
- Public Member Functions inherited from ImageResizer.Plugins.IPlugin
IPlugin Install (Config c)
 Installs the plugin in the specified Config instance. The plugin must handle all the work of loading settings, registering the plugin etc. More...
 
bool Uninstall (Config c)
 Uninstalls the plugin. Should reverse all changes made during Install More...
 
- Public Member Functions inherited from ImageResizer.Plugins.IVirtualImageProvider
bool FileExists (string virtualPath, NameValueCollection queryString)
 Returns true if the specified file exists. More...
 
IVirtualFile GetFile (string virtualPath, NameValueCollection queryString)
 Returns a virtual file instance for the specified path and querystring. More...
 

Protected Member Functions

override Stream GetStream (object source, ResizeSettings settings, ref bool disposeStream, out string path, out bool restoreStreamPosition)
 Allows .Build and .LoadImage to resize remote URLs More...
 
- Protected Member Functions inherited from ImageResizer.Resizing.AbstractImageProcessor
virtual void PreLoadImage (ref object source, ref string path, ref bool disposeSource, ref ResizeSettings settings)
 Extend this to allow additional types of source objects to be accepted by transforming them into Bitmap instances. More...
 
virtual RequestedAction PostDecodeStream (ref Bitmap img, ResizeSettings settings)
 Extend this to modify the Bitmap instance after it has been decoded by DecodeStream or DecodeStreamFailed More...
 
virtual void PreAcquireStream (ref object dest, ResizeSettings settings)
 Extend this to allow additional types of destination objects to be accepted by transforming them into a stream. More...
 
virtual RequestedAction BuildJob (ImageResizer.ImageJob job)
 The method to override if you want to replace the entire pipeline. All Build() calls call this method first. Does nothing in ImageBuilder More...
 
virtual RequestedAction buildToStream (Bitmap source, Stream dest, ResizeSettings settings)
 Called for Build() calls that want the result encoded. (Not for Bitmap Build(source,settings) calls. Only override this method if you need to replace the behavior of image encoding and image processing together, such as adding support for resizing multi-page TIFF files or animated GIFs. More...
 
virtual Bitmap buildToBitmap (Bitmap source, ResizeSettings settings, bool transparencySupported)
 Most calls funnel through here. Default behavior configures an ImageState instance and calls Process(imageState); Shouldn't be overriden for any reason I can think of - use the appropriate virtual method under Process(). If an extension returns a Bitmap instance, it will be used instead of the default behavior. Does NOT dispose of 'source' or 'source's underlying stream. More...
 
virtual RequestedAction OnProcess (ImageState s)
 Process.0 First step of the Process() method. Can replace the entire Process method if RequestAction.Cancel is returned. Can be used to add points to translate (for image maps), and also to modify the settings More...
 
virtual RequestedAction PrepareSourceBitmap (ImageState s)
 Process.1 Switches the bitmap to the correct frame or page, and applies source flipping commands. More...
 
virtual RequestedAction PostPrepareSourceBitmap (ImageState s)
 Process.2 Extend this to apply any pre-processing to the source bitmap that needs to occur before Layout begins More...
 
virtual RequestedAction Layout (ImageState s)
 Process.3(Layout).0: This is the last point at which points to translate should be added. Only return RequestedAction.Cancel if you wish to replace the entire Layout sequence logic. More...
 
virtual RequestedAction FlipExistingPoints (ImageState s)
 Process.3(Layout).1: This is where the points in the layout are flipped the same way the source bitmap was flipped (unless their flags specify otherwise) More...
 
virtual RequestedAction LayoutImage (ImageState s)
 Process.3(Layout).2: Rings 'image' and 'imageArea' are added to the layout. More...
 
virtual RequestedAction PostLayoutImage (ImageState s)
 Process.3(Layout).3: Add rings here to insert them between the image area and the padding More...
 
virtual RequestedAction LayoutPadding (ImageState s)
 Process.3(Layout).4: Ring "padding" is added to the layout More...
 
virtual RequestedAction PostLayoutPadding (ImageState s)
 Process.3(Layout).5: Add rings here to insert them between the padding and the border More...
 
virtual RequestedAction LayoutBorder (ImageState s)
 Process.3(Layout).6: Ring "border" is added to the layout More...
 
virtual RequestedAction PostLayoutBorder (ImageState s)
 Process.3(Layout).7: Add rings here to insert them between the border and the effect rings More...
 
virtual RequestedAction LayoutEffects (ImageState s)
 Process.3(Layout).8: Effects such as 'shadow' are added here. More...
 
virtual RequestedAction PostLayoutEffects (ImageState s)
 Process.3(Layout).9: Add rings here to insert them between the effects and the margin More...
 
virtual RequestedAction LayoutMargin (ImageState s)
 Process.3(Layout).10: Margins are added to the layout More...
 
virtual RequestedAction PostLayoutMargin (ImageState s)
 Process.3(Layout).11: Add rings here to insert them around the margin. Rings will be outermost More...
 
virtual RequestedAction LayoutRotate (ImageState s)
 Process.3(Layout).anytime: Occurs when the layout is rotated. May be called anytime during Layout() More...
 
virtual RequestedAction PostLayoutRotate (ImageState s)
 Process.3(Layout).anytime: Occurs after the layout is rotated. May be called anytime during Layout() More...
 
virtual RequestedAction LayoutNormalize (ImageState s)
 Process.3(Layout).anytime: Occurs when the layout is normalized to 0,0. May be called anytime during Layout() More...
 
virtual RequestedAction PostLayoutNormalize (ImageState s)
 Process.3(Layout).anytime: Occurs after the layout is normalized. May be called anytime during Layout() More...
 
virtual RequestedAction LayoutRound (ImageState s)
 Process.3(Layout).anytime: Occurs when the layout point values are rounded to integers. May be called anytime during Layout() More...
 
virtual RequestedAction PostLayoutRound (ImageState s)
 Process.3(Layout).anytime: Occurs after the layout point values are rounded to integers. May be called anytime during Layout() More...
 
virtual RequestedAction EndLayout (ImageState s)
 Process.3(Layout).12: Occurs once layout has finished. No more changes should occur to points or rings in the layout after this method. destSize is calculated here. More...
 
virtual RequestedAction PrepareDestinationBitmap (ImageState s)
 Process.4: The destination bitmap is created and sized based destSize. A graphics object is initialized for rendering. More...
 
virtual RequestedAction Render (ImageState s)
 Process.5(Render) Rendering. Do not return RequestedAction.Cancel unless you want to replace the entire rendering system. More...
 
virtual RequestedAction RenderBackground (ImageState s)
 Process.5(Render).1 The background color is rendered More...
 
virtual RequestedAction PostRenderBackground (ImageState s)
 Process.5(Render).2 After the background color is rendered More...
 
virtual RequestedAction RenderEffects (ImageState s)
 Process.5(Render).3 Effects (such as a drop shadow or outer glow) are rendered More...
 
virtual RequestedAction PostRenderEffects (ImageState s)
 Process.5(Render).4 After outer effects are rendered More...
 
virtual RequestedAction RenderPadding (ImageState s)
 Process.5(Render).5 Image padding is drawn More...
 
virtual RequestedAction PostRenderPadding (ImageState s)
 Process.5(Render).6 After image padding is drawn More...
 
virtual RequestedAction CreateImageAttribues (ImageState s)
 Process.5(Render).7: An ImageAttributes instance is created if it doesn't already exist. More...
 
virtual RequestedAction PostCreateImageAttributes (ImageState s)
 Process.5(Render).8: The ImageAttributes instance exists and can be modified or replaced. More...
 
virtual RequestedAction PreRenderImage (ImageState s)
 Process.5(Render).9: Plugins have a chance to pre-process the source image before it gets rendered, and save it to s.preRenderBitmap More...
 
virtual RequestedAction RenderImage (ImageState s)
 Process.5(Render).10: The image is copied to the destination parallelogram specified by ring 'image'. More...
 
virtual RequestedAction PostRenderImage (ImageState s)
 Process.5(Render).11: After the image is drawn More...
 
virtual RequestedAction RenderBorder (ImageState s)
 Process.5(Render).12: The border is rendered More...
 
virtual RequestedAction PostRenderBorder (ImageState s)
 Process.5(Render).13: After the border is drawn More...
 
virtual RequestedAction PreRenderOverlays (ImageState s)
 Process.5(Render).14: Any last-minute changes before watermarking or overlays are applied More...
 
virtual RequestedAction RenderOverlays (ImageState s)
 Process.5(Render).15: Watermarks can be rendered here. All image processing should be done More...
 
virtual RequestedAction PreFlushChanges (ImageState s)
 Process.5(Render).16: Called before changes are flushed and the graphics object is destroyed. More...
 
virtual RequestedAction FlushChanges (ImageState s)
 Process.5(Render).17: Changes are flushed to the bitmap here and the graphics object is destroyed. More...
 
virtual RequestedAction PostFlushChanges (ImageState s)
 Process.5(Render).18: Changes have been flushed to the bitmap, but the final bitmap has not been flipped yet. More...
 
virtual RequestedAction ProcessFinalBitmap (ImageState s)
 Process.6: Non-rendering changes to the bitmap object occur here, such as flipping. The graphics object is unavailable. More...
 
virtual RequestedAction EndProcess (ImageState s)
 Process.7: Layout and rendering are both complete. More...
 

Protected Attributes

string remotePrefix = "~/remote"
 
- Protected Attributes inherited from ImageResizer.Resizing.AbstractImageProcessor
volatile IEnumerable
< BuilderExtension
exts
 Contains the set of extensions that are called for every method. More...
 

Properties

static string Base64UrlKey [get]
 
static string HmacKey [get]
 
int AllowedRedirects [get, set]
 How many redirects to follow before throwing an exception. Defaults to 5. More...
 
static RemoteReaderPlugin Current [get]
 Returns the currently registered RemoteReaderPlugin, or adds a new RemoteReaderPlugin automatically if one is not registered. More...
 

Events

RemoteRequest AllowRemoteRequest
 Allows you to perform programmatic white or blacklisting of remote URLs More...
 

Detailed Description

Definition at line 19 of file RemoteReaderPlugin.cs.

Member Function Documentation

string ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin.CreateSignedUrl ( string  remoteUrl,
NameValueCollection  settings 
)
inline

Generates a signed domain-relative URL in the form "/app/remote.jpg.ashx?width=200&amp;urlb64=aHnSh3haSh...&amp;hmac=913f3KJGK3hj"

Parameters
remoteUrl
settings
Returns

Definition at line 144 of file RemoteReaderPlugin.cs.

144  {
145  settings[Base64UrlKey] = PathUtils.ToBase64U(remoteUrl);
146  settings[HmacKey] = SignData(settings[Base64UrlKey]);
147  return remotePrefix + ".jpg.ashx" + PathUtils.BuildQueryString(settings);
148  }
override Stream ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin.GetStream ( object  source,
ResizeSettings  settings,
ref bool  disposeStream,
out string  path,
out bool  restoreStreamPosition 
)
inlineprotectedvirtual

Allows .Build and .LoadImage to resize remote URLs

Parameters
source
settings
disposeStream
path
restoreStreamPosition
Returns

Reimplemented from ImageResizer.Resizing.AbstractImageProcessor.

Definition at line 89 of file RemoteReaderPlugin.cs.

89  {
90  //Turn remote URLs into URI instances
91  if (source is string && (((string)source).StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
92  ((string)source).StartsWith("https://", StringComparison.OrdinalIgnoreCase))) {
93  if (Uri.IsWellFormedUriString((string)source, UriKind.Absolute))
94  source = new Uri((string)source);
95 
96  }
97  restoreStreamPosition = false;
98  path = null;
99  //Turn URI instances into streams
100  if (source is Uri) {
101  path = ((Uri)source).ToString();
102  return GetUriStream((Uri)source);
103  }
104  return null;
105  }
Stream GetUriStream(Uri uri, int maxRedirects=-1)
Returns a stream of the HTTP response to the specified URL with a 15 second timeout. Throws a FileNotFoundException instead of a WebException for 404 errors. Can throw a variety of exceptions: ProtocolViolationException, WebException, FileNotFoundException, SecurityException, NotSupportedException?, and InvalidOperationException?.
Stream ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin.GetUriStream ( Uri  uri,
int  maxRedirects = -1 
)
inline

Returns a stream of the HTTP response to the specified URL with a 15 second timeout. Throws a FileNotFoundException instead of a WebException for 404 errors. Can throw a variety of exceptions: ProtocolViolationException, WebException, FileNotFoundException, SecurityException, NotSupportedException?, and InvalidOperationException?.

Parameters
uri
maxRedirects
Returns

Definition at line 302 of file RemoteReaderPlugin.cs.

302  {
303  if (maxRedirects == -1) maxRedirects = AllowedRedirects;
304 
305  HttpWebResponse response = null;
306  try {
307  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
308  request.Timeout = 15000; //Default to 15 seconds. Browser timeout is usually 30.
309 
310  //This is IDisposable, but only disposes the stream we are returning. So we can't dispose it, and don't need to
311  response = request.GetResponse() as HttpWebResponse;
312  return response.GetResponseStream();
313  } catch (WebException e) {
314  var resp = e.Response as HttpWebResponse;
315 
316  if (e.Status == WebExceptionStatus.ProtocolError && resp != null) {
317  if (resp.StatusCode == HttpStatusCode.NotFound) throw new FileNotFoundException("404 error: \"" + uri.ToString() + "\" not found.", e);
318 
319  if (resp.StatusCode == HttpStatusCode.Forbidden) throw new HttpException(403, "403 Not Authorized (from remote server) for : \"" + uri.ToString() + "\".", e);
320  if (resp.StatusCode == HttpStatusCode.Moved ||
321  resp.StatusCode == HttpStatusCode.Redirect) {
322  if (maxRedirects < 1) throw new HttpException(500, "Too many redirects, stopped while looking for \"" + uri.ToString() + "\".");
323  string loc = resp.GetResponseHeader("Location");
324  if (!string.IsNullOrEmpty(loc) && Uri.IsWellFormedUriString(loc, UriKind.RelativeOrAbsolute)) {
325  Uri newLoc = Uri.IsWellFormedUriString(loc, UriKind.Absolute) ? new Uri(loc) : new Uri(uri, new Uri(loc));
326  response.Close(); response = null;
327  return GetUriStream(newLoc, maxRedirects - 1);
328  }
329  }
330  }
331  //if (resp != null)resp.Close();
332  if (response != null) response.Close();
333  throw e;
334  }
335  }
Stream GetUriStream(Uri uri, int maxRedirects=-1)
Returns a stream of the HTTP response to the specified URL with a 15 second timeout. Throws a FileNotFoundException instead of a WebException for 404 errors. Can throw a variety of exceptions: ProtocolViolationException, WebException, FileNotFoundException, SecurityException, NotSupportedException?, and InvalidOperationException?.
int AllowedRedirects
How many redirects to follow before throwing an exception. Defaults to 5.
RemoteRequestEventArgs ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin.ParseRequest ( string  virtualPath,
NameValueCollection  query 
)
inline

Parses the specified path and querystring. Verifies the hmac signature for querystring specified paths, parses the human-friendly syntax for that syntax. Verifies the URL is properly formed. Returns an object containing the remote URL, querystring remainder, and a flag stating whether the request was signed or not. Incorrectly signed requests immediately throw an exception.

Parameters
virtualPath
query
Returns

Definition at line 184 of file RemoteReaderPlugin.cs.

184  {
185  query = new NameValueCollection(query);
186  if (!IsRemotePath(virtualPath)) return null;
187 
188  RemoteRequestEventArgs args = new RemoteRequestEventArgs();
189  args.SignedRequest = false;
190  args.QueryString = query;
191 
192  if (!string.IsNullOrEmpty(query[Base64UrlKey])) {
193  string data = query[Base64UrlKey];
194  string hmac = query[HmacKey];
195  query.Remove(Base64UrlKey);
196  query.Remove(HmacKey);
197  if (!SignData(data).Equals(hmac))
198  throw new ImageProcessingException("Invalid request! This request was not properly signed, or has been tampered with since transmission.");
199  args.RemoteUrl = PathUtils.FromBase64UToString(data);
200  args.SignedRequest = true;
201  } else {
202  args.RemoteUrl = "http://" + ReplaceInLeadingSegment(virtualPath.Substring(remotePrefix.Length).TrimStart('/', '\\'), "_", ".");
203  args.RemoteUrl = Uri.EscapeUriString(args.RemoteUrl);
204  }
205  if (!Uri.IsWellFormedUriString(args.RemoteUrl, UriKind.Absolute))
206  throw new ImageProcessingException("Invalid request! The specified Uri is invalid: " + args.RemoteUrl);
207  return args;
208  }

Property Documentation

int ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin.AllowedRedirects
getset

How many redirects to follow before throwing an exception. Defaults to 5.

Definition at line 42 of file RemoteReaderPlugin.cs.

RemoteReaderPlugin ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin.Current
staticget

Returns the currently registered RemoteReaderPlugin, or adds a new RemoteReaderPlugin automatically if one is not registered.

Definition at line 132 of file RemoteReaderPlugin.cs.

Event Documentation

RemoteRequest ImageResizer.Plugins.RemoteReader.RemoteReaderPlugin.AllowRemoteRequest

Allows you to perform programmatic white or blacklisting of remote URLs

Definition at line 231 of file RemoteReaderPlugin.cs.


The documentation for this class was generated from the following file: