From dd0f384ec3b2fd86ec03aa0fb42387091b5430a7 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sun, 10 Mar 2024 16:03:08 -0400 Subject: Squashed commit of the following: commit df1fed9e668d9e629354b209fd9dba18301db5d7 Author: vnugent Date: Sun Mar 10 16:01:29 2024 -0400 refactor: primary constructor for HttpRequest commit 795e7d307b5aa90321f9867d3b6b2630e3d8f29b Author: vnugent Date: Sat Mar 9 16:30:43 2024 -0500 package updates commit c826c9f99d9ccd43e056bc7b7283146868733e85 Author: vnugent Date: Sat Mar 9 14:58:58 2024 -0500 feat: Some docs, and updated clr string erasure functionality commit cefe2c38d9093bff553aa46c2fcf08380c6e2aed Author: vnugent Date: Wed Mar 6 21:37:59 2024 -0500 chore: removed bad oauth token function, abstracted HttpServer commit d2ef0e78b27c68fb83d183d50beeeb7a5ba7cba8 Author: vnugent Date: Wed Mar 6 19:49:55 2024 -0500 chore: pluginbase logging, consitent proj files, some outdated readmes commit b7537cd283431f684b16d3008d3b45f8b063d489 Author: vnugent Date: Sat Mar 2 15:12:48 2024 -0500 feat: session handle, endpoints, and helper functions --- .../src/Endpoints/ResourceEndpointBase.cs | 34 ++++++++++++++++++---- .../src/Endpoints/UnprotectedWebEndpoint.cs | 8 ++--- .../src/Endpoints/VirtualEndpoint.cs | 20 +++++++------ 3 files changed, 43 insertions(+), 19 deletions(-) (limited to 'lib/Plugins.Essentials/src/Endpoints') diff --git a/lib/Plugins.Essentials/src/Endpoints/ResourceEndpointBase.cs b/lib/Plugins.Essentials/src/Endpoints/ResourceEndpointBase.cs index 7c72bc4..048c543 100644 --- a/lib/Plugins.Essentials/src/Endpoints/ResourceEndpointBase.cs +++ b/lib/Plugins.Essentials/src/Endpoints/ResourceEndpointBase.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials @@ -42,6 +42,7 @@ namespace VNLib.Plugins.Essentials.Endpoints /// public abstract class ResourceEndpointBase : VirtualEndpoint { + /// /// Default protection settings. Protection settings are the most /// secure by default, should be loosened an necessary @@ -288,6 +289,11 @@ namespace VNLib.Plugins.Essentials.Endpoints /// The results of the processing protected virtual VfReturnType AlternateMethod(HttpEntity entity, HttpMethod method) => VirtualClose(entity, HttpStatusCode.MethodNotAllowed); + /// + /// This method gets invoked when an incoming OPTIONS request to the endpoint has been requested. + /// + /// The entity to be processed + /// The result of the operation to return to the file processor protected virtual VfReturnType Options(HttpEntity entity) => VfReturnType.Forbidden; /// @@ -328,7 +334,8 @@ namespace VNLib.Plugins.Essentials.Endpoints /// The entity to close the connection for /// A object that will be serialized and returned to the client as JSON /// The operation result - public static VfReturnType VirtualOkJson(HttpEntity entity, T jsonValue) => VirtualCloseJson(entity, jsonValue, HttpStatusCode.OK); + public static VfReturnType VirtualOkJson(HttpEntity entity, T jsonValue) + => VirtualCloseJson(entity, jsonValue, HttpStatusCode.OK); /// /// Shortcut helper methods to a virtual skip response with a 200 OK status code @@ -338,7 +345,8 @@ namespace VNLib.Plugins.Essentials.Endpoints /// The json response /// The status code to return to the client /// The operation result - public static VfReturnType VirtualClose(HttpEntity entity, T webm, HttpStatusCode code) where T: WebMessage => VirtualCloseJson(entity, webm, code); + public static VfReturnType VirtualClose(HttpEntity entity, T webm, HttpStatusCode code) where T: WebMessage + => VirtualCloseJson(entity, webm, code); /// /// Shortcut helper methods to a virtual skip response with a given status code @@ -391,11 +399,10 @@ namespace VNLib.Plugins.Essentials.Endpoints /// The status code to return to the client /// The response content type /// The stream response to return to the user - /// The explicit length of the stream /// The operation result public static VfReturnType VirtualClose(HttpEntity entity, HttpStatusCode code, ContentType ct, Stream response) { - ArgumentNullException.ThrowIfNull(response, nameof(response)); + ArgumentNullException.ThrowIfNull(response); if (!response.CanSeek) { throw new IOException("The stream must be seekable when using implicit length"); @@ -404,6 +411,23 @@ namespace VNLib.Plugins.Essentials.Endpoints return VfReturnType.VirtualSkip; } + /// + /// Shortcut helper methods to a virtual skip response with a given status code, + /// and memory content to return to the client + /// + /// The entity to close the connection for + /// The status code to return to the client + /// The response content type + /// The stream response to return to the user + /// The length of the response data to send to the clien + /// The operation result + public static VfReturnType VirtualClose(HttpEntity entity, HttpStatusCode code, ContentType ct, IHttpStreamResponse response, long length) + { + ArgumentNullException.ThrowIfNull(response); + entity.CloseResponse(code, ct, response, length); + return VfReturnType.VirtualSkip; + } + /// /// Shortcut helper methods to a virtual skip response with a given status code, and /// a json payload to return to the client diff --git a/lib/Plugins.Essentials/src/Endpoints/UnprotectedWebEndpoint.cs b/lib/Plugins.Essentials/src/Endpoints/UnprotectedWebEndpoint.cs index 7a4364b..0d3623b 100644 --- a/lib/Plugins.Essentials/src/Endpoints/UnprotectedWebEndpoint.cs +++ b/lib/Plugins.Essentials/src/Endpoints/UnprotectedWebEndpoint.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials @@ -33,9 +33,7 @@ namespace VNLib.Plugins.Essentials.Endpoints public abstract class UnprotectedWebEndpoint : ResourceEndpointBase { /// - protected override ERRNO PreProccess(HttpEntity entity) - { - return base.PreProccess(entity) && entity.Session.IsSet && entity.Session.SessionType == Sessions.SessionType.Web; - } + protected override ERRNO PreProccess(HttpEntity entity) + => base.PreProccess(entity) && entity.Session.IsSet && entity.Session.SessionType == Sessions.SessionType.Web; } } \ No newline at end of file diff --git a/lib/Plugins.Essentials/src/Endpoints/VirtualEndpoint.cs b/lib/Plugins.Essentials/src/Endpoints/VirtualEndpoint.cs index 4ffe288..6d42ca7 100644 --- a/lib/Plugins.Essentials/src/Endpoints/VirtualEndpoint.cs +++ b/lib/Plugins.Essentials/src/Endpoints/VirtualEndpoint.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials @@ -47,19 +47,21 @@ namespace VNLib.Plugins.Essentials.Endpoints /// /// Sets the log and path and checks the values /// - /// The path this instance represents + /// The path this instance represents /// The log provider that will be used /// - protected void InitPathAndLog(string Path, ILogProvider log) + protected void InitPathAndLog(string path, ILogProvider log) { - if (string.IsNullOrWhiteSpace(Path) || Path[0] != '/') + ArgumentException.ThrowIfNullOrWhiteSpace(path); + ArgumentNullException.ThrowIfNull(log); + + if (path[0] != '/') { - throw new ArgumentException("Path must begin with a '/' character", nameof(Path)); + throw new ArgumentException("Path must begin with a '/' character", nameof(path)); } - //Store path - this.Path = Path; - //Store log - Log = log ?? throw new ArgumentNullException(nameof(log)); + + Path = path; + Log = log; } /// -- cgit