aboutsummaryrefslogtreecommitdiff
path: root/lib/Plugins.Essentials
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Plugins.Essentials')
-rw-r--r--lib/Plugins.Essentials/src/Endpoints/SemiConsistentVeTable.cs (renamed from lib/Plugins.Essentials/src/SemiConsistentVeTable.cs)7
-rw-r--r--lib/Plugins.Essentials/src/EventProcessor.cs37
-rw-r--r--lib/Plugins.Essentials/src/EventProcessorConfig.cs1
-rw-r--r--lib/Plugins.Essentials/src/Middleware/IHttpMiddleware.cs16
-rw-r--r--lib/Plugins.Essentials/src/Middleware/MiddlewareController.cs77
-rw-r--r--lib/Plugins.Essentials/src/VNLib.Plugins.Essentials.csproj8
6 files changed, 114 insertions, 32 deletions
diff --git a/lib/Plugins.Essentials/src/SemiConsistentVeTable.cs b/lib/Plugins.Essentials/src/Endpoints/SemiConsistentVeTable.cs
index e1706f4..09ab151 100644
--- a/lib/Plugins.Essentials/src/SemiConsistentVeTable.cs
+++ b/lib/Plugins.Essentials/src/Endpoints/SemiConsistentVeTable.cs
@@ -31,11 +31,10 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using VNLib.Net.Http;
-using VNLib.Plugins.Essentials.Endpoints;
-namespace VNLib.Plugins.Essentials
+namespace VNLib.Plugins.Essentials.Endpoints
{
- internal class SemiConsistentVeTable : IVirtualEndpointTable
+ internal sealed class SemiConsistentVeTable : IVirtualEndpointTable
{
/*
@@ -170,7 +169,7 @@ namespace VNLib.Plugins.Essentials
}
///<inheritdoc/>
- public bool TryGetEndpoint(string path, [NotNullWhen(true)] out IVirtualEndpoint<HttpEntity>? endpoint)
+ public bool TryGetEndpoint(string path, [NotNullWhen(true)] out IVirtualEndpoint<HttpEntity>? endpoint)
=> VirtualEndpoints.TryGetValue(path, out endpoint);
diff --git a/lib/Plugins.Essentials/src/EventProcessor.cs b/lib/Plugins.Essentials/src/EventProcessor.cs
index f052c56..ba7aa3c 100644
--- a/lib/Plugins.Essentials/src/EventProcessor.cs
+++ b/lib/Plugins.Essentials/src/EventProcessor.cs
@@ -28,7 +28,6 @@ using System.Net;
using System.Threading;
using System.Net.Sockets;
using System.Threading.Tasks;
-using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
@@ -40,8 +39,8 @@ using VNLib.Plugins.Essentials.Accounts;
using VNLib.Plugins.Essentials.Content;
using VNLib.Plugins.Essentials.Sessions;
using VNLib.Plugins.Essentials.Extensions;
-using VNLib.Plugins.Essentials.Middleware;
using VNLib.Plugins.Essentials.Endpoints;
+using VNLib.Plugins.Essentials.Middleware;
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
@@ -133,7 +132,8 @@ namespace VNLib.Plugins.Essentials
/// The internal service pool for the processor
/// </summary>
protected readonly HttpProcessorServicePool ServicePool = new([
- typeof(ISessionProvider), //Order must match the indexes above
+ //Order must match the indexes above
+ typeof(ISessionProvider),
typeof(IPageRouter),
typeof(IAccountSecurityProvider)
]);
@@ -157,6 +157,8 @@ namespace VNLib.Plugins.Essentials
get => ServicePool.ExchangeVersion(ref _accountSec, SEC_INDEX);
}
+ private readonly MiddlewareController _middleware = new(config);
+
///<inheritdoc/>
public virtual async ValueTask ClientConnectedAsync(IHttpEvent httpEvent)
{
@@ -169,8 +171,6 @@ namespace VNLib.Plugins.Essentials
ISessionProvider? sessions = ServicePool.ExchangeVersion(ref _sessions, SESS_INDEX);
IPageRouter? router = ServicePool.ExchangeVersion(ref _router, ROUTER_INDEX);
- LinkedListNode<IHttpMiddleware>? mwNode = config.MiddlewareChain.GetCurrentHead();
-
//event cancellation token
HttpEntity entity = new(httpEvent, this);
@@ -205,24 +205,10 @@ namespace VNLib.Plugins.Essentials
goto RespondAndExit;
}
- //Loop through nodes
- while(mwNode != null)
+ //Exec middleware
+ if(!await _middleware.ProcessAsync(entity))
{
- //Invoke mw handler on our event
- entity.EventArgs = await mwNode.ValueRef.ProcessAsync(entity);
-
- switch (entity.EventArgs.Routine)
- {
- //move next if continue is returned
- case FpRoutine.Continue:
- break;
-
- //Middleware completed the connection, time to exit
- default:
- goto RespondAndExit;
- }
-
- mwNode = mwNode.Next;
+ goto RespondAndExit;
}
if (!config.EndpointTable.IsEmpty)
@@ -257,6 +243,9 @@ namespace VNLib.Plugins.Essentials
RespondAndExit:
+ //Normal post-process
+ _middleware.PostProcess(entity);
+
//Call post processor method
PostProcessEntity(entity, ref entity.EventArgs);
}
@@ -744,5 +733,5 @@ namespace VNLib.Plugins.Essentials
return arr;
}
}
- }
-} \ No newline at end of file
+ }
+}
diff --git a/lib/Plugins.Essentials/src/EventProcessorConfig.cs b/lib/Plugins.Essentials/src/EventProcessorConfig.cs
index 8f401ac..6e101eb 100644
--- a/lib/Plugins.Essentials/src/EventProcessorConfig.cs
+++ b/lib/Plugins.Essentials/src/EventProcessorConfig.cs
@@ -29,6 +29,7 @@ using System.Collections.Frozen;
using System.Collections.Generic;
using VNLib.Utils.Logging;
+using VNLib.Plugins.Essentials.Endpoints;
using VNLib.Plugins.Essentials.Middleware;
namespace VNLib.Plugins.Essentials
diff --git a/lib/Plugins.Essentials/src/Middleware/IHttpMiddleware.cs b/lib/Plugins.Essentials/src/Middleware/IHttpMiddleware.cs
index 83e6a06..990d59b 100644
--- a/lib/Plugins.Essentials/src/Middleware/IHttpMiddleware.cs
+++ b/lib/Plugins.Essentials/src/Middleware/IHttpMiddleware.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Essentials
@@ -40,5 +40,19 @@ namespace VNLib.Plugins.Essentials.Middleware
/// <param name="entity">The entity to process</param>
/// <returns>The result of the operation</returns>
ValueTask<FileProcessArgs> ProcessAsync(HttpEntity entity);
+
+ /// <summary>
+ /// Post processes an HTTP entity with possible file selection. May optionally mutate the
+ /// current arguments before the event processor completes a response.
+ /// </summary>
+ /// <param name="entity">The entity that has been processes and is ready to close</param>
+ /// <param name="currentArgs">The current file processor arguments</param>
+ /// <remarks>
+ /// Generally this function should simply observe results as the entity may already have been
+ /// configured for a response, such as by a virtual routine. You should inspect the current arguments
+ /// before mutating the reference.
+ /// </remarks>
+ virtual void VolatilePostProcess(HttpEntity entity, ref FileProcessArgs currentArgs)
+ { }
}
}
diff --git a/lib/Plugins.Essentials/src/Middleware/MiddlewareController.cs b/lib/Plugins.Essentials/src/Middleware/MiddlewareController.cs
new file mode 100644
index 0000000..2ce62b3
--- /dev/null
+++ b/lib/Plugins.Essentials/src/Middleware/MiddlewareController.cs
@@ -0,0 +1,77 @@
+/*
+* Copyright (c) 2024 Vaughn Nugent
+*
+* Library: VNLib
+* Package: VNLib.Plugins.Essentials
+* File: MiddlewareController.cs
+*
+* MiddlewareController.cs is part of VNLib.Plugins.Essentials which is part
+* of the larger VNLib collection of libraries and utilities.
+*
+* VNLib.Plugins.Essentials is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* VNLib.Plugins.Essentials is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see https://www.gnu.org/licenses/.
+*/
+
+using System.Threading.Tasks;
+using System.Collections.Generic;
+
+namespace VNLib.Plugins.Essentials.Middleware
+{
+ internal sealed class MiddlewareController(EventProcessorConfig config)
+ {
+ private readonly IHttpMiddlewareChain _chain = config.MiddlewareChain;
+
+ public async ValueTask<bool> ProcessAsync(HttpEntity entity)
+ {
+ LinkedListNode<IHttpMiddleware>? mwNode = _chain.GetCurrentHead();
+
+ //Loop through nodes
+ while (mwNode != null)
+ {
+ //Invoke mw handler on our event
+ entity.EventArgs = await mwNode.ValueRef.ProcessAsync(entity);
+
+ switch (entity.EventArgs.Routine)
+ {
+ //move next if continue is returned
+ case FpRoutine.Continue:
+ break;
+
+ //Middleware completed the connection, time to exit the event processing
+ default:
+ return false;
+ }
+
+ mwNode = mwNode.Next;
+ }
+
+ return true;
+ }
+
+ public void PostProcess(HttpEntity entity)
+ {
+ LinkedListNode<IHttpMiddleware>? mwNode = _chain.GetCurrentHead();
+
+ //Loop through nodes
+ while (mwNode != null)
+ {
+ //Invoke mw handler on our event
+ mwNode.ValueRef.VolatilePostProcess(entity, ref entity.EventArgs);
+
+ mwNode = mwNode.Next;
+ }
+ }
+ }
+
+
+} \ No newline at end of file
diff --git a/lib/Plugins.Essentials/src/VNLib.Plugins.Essentials.csproj b/lib/Plugins.Essentials/src/VNLib.Plugins.Essentials.csproj
index 4da640a..3a21ac9 100644
--- a/lib/Plugins.Essentials/src/VNLib.Plugins.Essentials.csproj
+++ b/lib/Plugins.Essentials/src/VNLib.Plugins.Essentials.csproj
@@ -2,13 +2,15 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
+ <Nullable>enable</Nullable>
<RootNamespace>VNLib.Plugins.Essentials</RootNamespace>
<AssemblyName>VNLib.Plugins.Essentials</AssemblyName>
- <AnalysisLevel>latest-all</AnalysisLevel>
- <EnableNETAnalyzers>True</EnableNETAnalyzers>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
- <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <AnalysisLevel Condition="'$(BuildingInsideVisualStudio)' == true">latest-all</AnalysisLevel>
</PropertyGroup>
<PropertyGroup>