diff options
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs')
-rw-r--r-- | plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs index c1531f7..acceb0c 100644 --- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs +++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs @@ -35,38 +35,53 @@ namespace VNLib.Plugins.Essentials.Content.Routing.Model [Index(nameof(Id), IsUnique = true)] internal class Route : DbModelBase { + public const FpRoutine RewriteRoutine = (FpRoutine)50; + [Key] public override string Id { get; set; } public override DateTime Created { get; set; } public override DateTime LastModified { get; set; } public string Hostname { get; set; } + public string MatchPath { get; set; } + [Column("Privilage")] public long _privilage { get => (long)Privilage; set => Privilage = (ulong)value; } + [NotMapped] public ulong Privilage { get; set; } - public string Alternate { get; set; } - public FpRoutine Routine { get; set; } + public string? Alternate { get; set; } = string.Empty; + + public FpRoutine Routine { get; set; } + + public string? RewriteSearch { get; set; } /// <summary> - /// The processing arguments that match the route + /// Creates the <see cref="FileProcessArgs"/> to return to the processor + /// for the current rule, which may include rewriting the url. /// </summary> - [NotMapped] - public FileProcessArgs MatchArgs + /// <param name="entity">The connection to get the args for</param> + /// <returns>The <see cref="FileProcessArgs"/> for the connection</returns> + public FileProcessArgs GetArgs(HttpEntity entity) { - get + //Check for rewrite routine + if (Routine == RewriteRoutine) + { + //Rewrite the request url and return the args, processor will clean and parse url + string rewritten = entity.Server.Path.Replace(RewriteSearch!, Alternate!, StringComparison.OrdinalIgnoreCase); + + //Set to rewrite args + return new FileProcessArgs(FpRoutine.ServeOther, rewritten); + } + else { - return new FileProcessArgs() - { - Alternate = this.Alternate, - Routine = (FpRoutine) Routine - }; + return new FileProcessArgs(Routine, Alternate!); } } } |