diff options
author | vnugent <public@vaughnnugent.com> | 2024-03-10 16:03:08 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-03-10 16:03:08 -0400 |
commit | dd0f384ec3b2fd86ec03aa0fb42387091b5430a7 (patch) | |
tree | 23f6e1c99fe2c0d1c0c12b0a40dba2d7f35e90c6 /lib/Plugins.Essentials/src/Endpoints | |
parent | b679ddd4e647ac915febd0d5a5e488a1e8e48842 (diff) |
Squashed commit of the following:
commit df1fed9e668d9e629354b209fd9dba18301db5d7
Author: vnugent <public@vaughnnugent.com>
Date: Sun Mar 10 16:01:29 2024 -0400
refactor: primary constructor for HttpRequest
commit 795e7d307b5aa90321f9867d3b6b2630e3d8f29b
Author: vnugent <public@vaughnnugent.com>
Date: Sat Mar 9 16:30:43 2024 -0500
package updates
commit c826c9f99d9ccd43e056bc7b7283146868733e85
Author: vnugent <public@vaughnnugent.com>
Date: Sat Mar 9 14:58:58 2024 -0500
feat: Some docs, and updated clr string erasure functionality
commit cefe2c38d9093bff553aa46c2fcf08380c6e2aed
Author: vnugent <public@vaughnnugent.com>
Date: Wed Mar 6 21:37:59 2024 -0500
chore: removed bad oauth token function, abstracted HttpServer
commit d2ef0e78b27c68fb83d183d50beeeb7a5ba7cba8
Author: vnugent <public@vaughnnugent.com>
Date: Wed Mar 6 19:49:55 2024 -0500
chore: pluginbase logging, consitent proj files, some outdated readmes
commit b7537cd283431f684b16d3008d3b45f8b063d489
Author: vnugent <public@vaughnnugent.com>
Date: Sat Mar 2 15:12:48 2024 -0500
feat: session handle, endpoints, and helper functions
Diffstat (limited to 'lib/Plugins.Essentials/src/Endpoints')
3 files changed, 43 insertions, 19 deletions
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 /// </summary> public abstract class ResourceEndpointBase : VirtualEndpoint<HttpEntity> { + /// <summary> /// 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 /// <returns>The results of the processing</returns> protected virtual VfReturnType AlternateMethod(HttpEntity entity, HttpMethod method) => VirtualClose(entity, HttpStatusCode.MethodNotAllowed); + /// <summary> + /// This method gets invoked when an incoming OPTIONS request to the endpoint has been requested. + /// </summary> + /// <param name="entity">The entity to be processed</param> + /// <returns>The result of the operation to return to the file processor</returns> protected virtual VfReturnType Options(HttpEntity entity) => VfReturnType.Forbidden; /// <summary> @@ -328,7 +334,8 @@ namespace VNLib.Plugins.Essentials.Endpoints /// <param name="entity">The entity to close the connection for</param> /// <param name="jsonValue">A object that will be serialized and returned to the client as JSON</param> /// <returns>The <see cref="VfReturnType.VirtualSkip"/> operation result</returns> - public static VfReturnType VirtualOkJson<T>(HttpEntity entity, T jsonValue) => VirtualCloseJson(entity, jsonValue, HttpStatusCode.OK); + public static VfReturnType VirtualOkJson<T>(HttpEntity entity, T jsonValue) + => VirtualCloseJson(entity, jsonValue, HttpStatusCode.OK); /// <summary> /// Shortcut helper methods to a virtual skip response with a 200 OK status code @@ -338,7 +345,8 @@ namespace VNLib.Plugins.Essentials.Endpoints /// <param name="webm">The <see cref="WebMessage"/> json response</param> /// <param name="code">The status code to return to the client</param> /// <returns>The <see cref="VfReturnType.VirtualSkip"/> operation result</returns> - public static VfReturnType VirtualClose<T>(HttpEntity entity, T webm, HttpStatusCode code) where T: WebMessage => VirtualCloseJson(entity, webm, code); + public static VfReturnType VirtualClose<T>(HttpEntity entity, T webm, HttpStatusCode code) where T: WebMessage + => VirtualCloseJson(entity, webm, code); /// <summary> /// Shortcut helper methods to a virtual skip response with a given status code @@ -391,11 +399,10 @@ namespace VNLib.Plugins.Essentials.Endpoints /// <param name="code">The status code to return to the client</param> /// <param name="ct">The response content type</param> /// <param name="response">The stream response to return to the user</param> - /// <param name="length">The explicit length of the stream</param> /// <returns>The <see cref="VfReturnType.VirtualSkip"/> operation result</returns> 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"); @@ -405,6 +412,23 @@ namespace VNLib.Plugins.Essentials.Endpoints } /// <summary> + /// Shortcut helper methods to a virtual skip response with a given status code, + /// and memory content to return to the client + /// </summary> + /// <param name="entity">The entity to close the connection for</param> + /// <param name="code">The status code to return to the client</param> + /// <param name="ct">The response content type</param> + /// <param name="response">The stream response to return to the user</param> + /// <param name="length">The length of the response data to send to the clien</param> + /// <returns>The <see cref="VfReturnType.VirtualSkip"/> operation result</returns> + 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; + } + + /// <summary> /// Shortcut helper methods to a virtual skip response with a given status code, and /// a json payload to return to the client /// </summary> 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 { ///<inheritdoc/> - 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 /// <summary> /// Sets the log and path and checks the values /// </summary> - /// <param name="Path">The path this instance represents</param> + /// <param name="path">The path this instance represents</param> /// <param name="log">The log provider that will be used</param> /// <exception cref="ArgumentException"></exception> - 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; } ///<inheritdoc/> |