Skip to content

Commit

Permalink
Added ApplyDefaultCommandsToQuerylessUrls route option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Sigley committed Aug 11, 2023
1 parent e2a80fd commit b444710
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Imageflow.Server.Configuration/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ public ImageflowMiddlewareOptions GetImageflowMiddlewareOptions(){
}

}

if (config.RouteDefaults?.ApplyDefaultCommandsToQuerylessUrls ?? false){
options.SetApplyDefaultCommandsToQuerylessUrls(true);
}

// set security options
var securityOptions = new SecurityOptions();
if (config.Security?.MaxDecodeResolution != null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ internal class RouteBase : ITomlMetadataProvider, IValidationCapable
// public RouteSource? Source { get; set; }
public string? CacheControl { get; set; }
public string? ApplyDefaultCommands { get; set; }
public bool? ApplyDefaultCommandsToQuerylessUrls { get; set; }
// public string? ApplyOverrideCommands { get; set; }
// public string? RequireSignature { get; set; }

Expand Down
1 change: 1 addition & 0 deletions src/Imageflow.Server.Configuration/minimal.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ lowercase_path_remainder = false
allow_extensionless_urls = false
cache_control = "public, max-age=2592000"
apply_default_commands = "quality=76&webp.quality=70&f.sharpen=23&down.filter=mitchell"
apply_default_commands_to_queryless_urls = false

[[routes]]
prefix = '/images/'
Expand Down
2 changes: 1 addition & 1 deletion src/Imageflow.Server/ImageJobInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private bool ProcessRewritesAndAuthorization(HttpContext context, ImageflowMiddl
}

// Set defaults if keys are missing, but at least 1 supported key is present
if (PathHelpers.SupportedQuerystringKeys.Any(args.Query.ContainsKey))
if (middlewareOptions.ApplyDefaultCommandsToQuerylessUrls || PathHelpers.SupportedQuerystringKeys.Any(args.Query.ContainsKey))
{
foreach (var pair in middlewareOptions.CommandDefaults)
{
Expand Down
14 changes: 13 additions & 1 deletion src/Imageflow.Server/ImageflowMiddlewareOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public class ImageflowMiddlewareOptions


internal readonly Dictionary<string, string> CommandDefaults = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

public bool ApplyDefaultCommandsToQuerylessUrls { get; set; } = false;

internal readonly Dictionary<string, PresetOptions> Presets = new Dictionary<string, PresetOptions>(StringComparer.OrdinalIgnoreCase);

internal readonly List<ExtensionlessPath> ExtensionlessPaths = new List<ExtensionlessPath>();
Expand Down Expand Up @@ -242,5 +243,16 @@ public ImageflowMiddlewareOptions SetDefaultCacheControlString(string cacheContr
DefaultCacheControlString = cacheControlString;
return this;
}

/// <summary>
/// Set to true have the command defaults to all urls, not just ones containing a valid query command.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public ImageflowMiddlewareOptions SetApplyDefaultCommandsToQuerylessUrls(bool value)
{
this.ApplyDefaultCommandsToQuerylessUrls = value;
return this;
}
}
}

0 comments on commit b444710

Please sign in to comment.