1616namespace SixLabors . ImageSharp . Web . TagHelpers ;
1717
1818/// <summary>
19- /// A TagHelper implementation targeting <img> element that allows the automatic generation of HMAC protected processing commands.
19+ /// A <see cref=" TagHelper"/> implementation targeting <img> element that allows the automatic generation image processing commands.
2020/// </summary>
2121[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + WidthAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
2222[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + HeightAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
2323[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + AnchorAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
24- [ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + RModeAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
24+ [ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + ModeAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
2525[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + XyAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
26- [ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + RColorAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
26+ [ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + ColorAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
2727[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + CompandAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
2828[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + OrientAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
2929[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + AutoOrientAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
3030[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + FormatAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
3131[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + BgColorAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
3232[ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + QualityAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
33- [ HtmlTargetElement ( "img" , Attributes = SrcAttributeName + "," + HMACAttributeName , TagStructure = TagStructure . WithoutEndTag ) ]
3433public class ImageTagHelper : UrlResolutionTagHelper
3534{
3635 private const string SrcAttributeName = "src" ;
3736 private const string AttributePrefix = "imagesharp-" ;
3837 private const string WidthAttributeName = AttributePrefix + ResizeWebProcessor . Width ;
3938 private const string HeightAttributeName = AttributePrefix + ResizeWebProcessor . Height ;
4039 private const string AnchorAttributeName = AttributePrefix + ResizeWebProcessor . Anchor ;
41- private const string RModeAttributeName = AttributePrefix + ResizeWebProcessor . Mode ;
40+ private const string ModeAttributeName = AttributePrefix + ResizeWebProcessor . Mode ;
4241 private const string XyAttributeName = AttributePrefix + ResizeWebProcessor . Xy ;
43- private const string RColorAttributeName = AttributePrefix + ResizeWebProcessor . Color ;
42+ private const string ColorAttributeName = AttributePrefix + ResizeWebProcessor . Color ;
4443 private const string CompandAttributeName = AttributePrefix + ResizeWebProcessor . Compand ;
4544 private const string OrientAttributeName = AttributePrefix + ResizeWebProcessor . Orient ;
4645 private const string SamplerAttributeName = AttributePrefix + ResizeWebProcessor . Sampler ;
4746 private const string AutoOrientAttributeName = AttributePrefix + AutoOrientWebProcessor . AutoOrient ;
4847 private const string FormatAttributeName = AttributePrefix + FormatWebProcessor . Format ;
4948 private const string BgColorAttributeName = AttributePrefix + BackgroundColorWebProcessor . Color ;
5049 private const string QualityAttributeName = AttributePrefix + QualityWebProcessor . Quality ;
51- private const string HMACAttributeName = AttributePrefix + RequestAuthorizationUtilities . TokenCommand ;
5250
5351 private readonly ImageSharpMiddlewareOptions options ;
5452 private readonly CultureInfo parserCulture ;
5553 private readonly char separator ;
56- private readonly RequestAuthorizationUtilities authorizationUtilities ;
5754
5855 /// <summary>
5956 /// Initializes a new instance of the <see cref="ImageTagHelper"/> class.
@@ -77,10 +74,11 @@ public ImageTagHelper(
7774 ? CultureInfo . InvariantCulture
7875 : CultureInfo . CurrentCulture ;
7976 this . separator = this . parserCulture . TextInfo . ListSeparator [ 0 ] ;
80-
81- this . authorizationUtilities = authorizationUtilities ;
8277 }
8378
79+ /// <inheritdoc/>
80+ public override int Order => 1 ;
81+
8482 /// <summary>
8583 /// Gets or sets the src.
8684 /// </summary>
@@ -111,7 +109,7 @@ public ImageTagHelper(
111109 /// <summary>
112110 /// Gets or sets the resize mode.
113111 /// </summary>
114- [ HtmlAttributeName ( RModeAttributeName ) ]
112+ [ HtmlAttributeName ( ModeAttributeName ) ]
115113 public ResizeMode ? ResizeMode { get ; set ; }
116114
117115 /// <summary>
@@ -129,7 +127,7 @@ public ImageTagHelper(
129127 /// <summary>
130128 /// Gets or sets the color to use as a background when padding an image.
131129 /// </summary>
132- [ HtmlAttributeName ( RColorAttributeName ) ]
130+ [ HtmlAttributeName ( ColorAttributeName ) ]
133131 public Color ? PadColor { get ; set ; }
134132
135133 /// <summary>
@@ -180,24 +178,17 @@ public ImageTagHelper(
180178 [ HtmlAttributeName ( QualityAttributeName ) ]
181179 public int ? Quality { get ; set ; }
182180
183- /// <summary>
184- /// Gets or sets a value indicating whether to append a HMAC token to the request.
185- /// This value is always <see langword="true"/>. HMAC token usage is controlled by populating the
186- /// <see cref="ImageSharpMiddlewareOptions.HMACSecretKey"/> property.
187- /// </summary>
188- [ HtmlAttributeName ( HMACAttributeName ) ]
189- #pragma warning disable CA1822 // Mark members as static
190- public bool AppendHMAC { get => true ; set => _ = true ; }
191- #pragma warning restore CA1822 // Mark members as static
192-
193181 /// <inheritdoc />
194182 public override void Process ( TagHelperContext context , TagHelperOutput output )
195183 {
196184 Guard . NotNull ( context , nameof ( context ) ) ;
197185 Guard . NotNull ( output , nameof ( output ) ) ;
198186
199187 string ? src = output . Attributes [ SrcAttributeName ] ? . Value as string ?? this . Src ;
200- if ( string . IsNullOrWhiteSpace ( src ) || src . StartsWith ( "data" , StringComparison . OrdinalIgnoreCase ) )
188+ if ( string . IsNullOrWhiteSpace ( src )
189+ || src . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase )
190+ || src . StartsWith ( "ftp" , StringComparison . OrdinalIgnoreCase )
191+ || src . StartsWith ( "data" , StringComparison . OrdinalIgnoreCase ) )
201192 {
202193 base . Process ( context , output ) ;
203194 return ;
@@ -209,24 +200,16 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
209200 CommandCollection commands = new ( ) ;
210201 this . AddProcessingCommands ( context , output , commands , this . parserCulture ) ;
211202
212- byte [ ] secret = this . options . HMACSecretKey ;
213- if ( commands . Count > 0 || secret ? . Length > 0 )
203+ if ( commands . Count > 0 )
214204 {
215205 // Retrieve the TagHelperOutput variation of the "src" attribute in case other TagHelpers in the
216206 // pipeline have touched the value. If the value is already encoded this helper may
217207 // not function properly.
218- src = output . Attributes [ SrcAttributeName ] . Value as string ;
219- if ( secret ? . Length > 0 )
220- {
221- string hash = this . authorizationUtilities . ComputeHMAC ( src ! , commands , secret ) ;
222- commands . Add ( RequestAuthorizationUtilities . TokenCommand , hash ) ;
223- }
224-
208+ src = output . Attributes [ SrcAttributeName ] ? . Value as string ;
225209 src = AddQueryString ( src , commands ) ;
210+ output . Attributes . SetAttribute ( SrcAttributeName , src ) ;
211+ this . Src = src ;
226212 }
227-
228- this . Src = src ;
229- output . Attributes . SetAttribute ( SrcAttributeName , src ) ;
230213 }
231214
232215 /// <summary>
0 commit comments