From 765d3d328af49f92f1d0b296bfba2d7791e0cdf5 Mon Sep 17 00:00:00 2001 From: vnugent Date: Mon, 29 May 2023 17:35:08 -0400 Subject: XML file backed content routing, no more db required --- .../src/Model/Route.cs | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs') 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; } /// - /// The processing arguments that match the route + /// Creates the to return to the processor + /// for the current rule, which may include rewriting the url. /// - [NotMapped] - public FileProcessArgs MatchArgs + /// The connection to get the args for + /// The for the connection + 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!); } } } -- cgit