From 0e4cc8b11f077ccc966ea96af5fe6166ec485dca Mon Sep 17 00:00:00 2001 From: mdaneri Date: Fri, 29 Nov 2024 16:58:21 -0800 Subject: [PATCH] Code cleanup --- examples/Web-SelfSigned.ps1 | 39 +++++++++++++++++++++++++++++++ src/Listener/PodeHttpRequest.cs | 18 -------------- src/Listener/PodeSignalRequest.cs | 14 ----------- src/Listener/PodeSmtpRequest.cs | 28 +++++----------------- src/Listener/PodeTcpRequest.cs | 7 ------ 5 files changed, 45 insertions(+), 61 deletions(-) create mode 100644 examples/Web-SelfSigned.ps1 diff --git a/examples/Web-SelfSigned.ps1 b/examples/Web-SelfSigned.ps1 new file mode 100644 index 000000000..94a2e6356 --- /dev/null +++ b/examples/Web-SelfSigned.ps1 @@ -0,0 +1,39 @@ +<# +.SYNOPSIS + A sample PowerShell script to set up a HTTPS Pode server with a self-sign certificate + +.DESCRIPTION + This script sets up a Pode server listening on port 8081 in HTTPS + +.EXAMPLE + To run the sample: ./Web-SelfSigned.ps1 + +.LINK + https://github.com/Badgerati/Pode/blob/develop/examples/Web-SelfSigned.ps1 + +.NOTES + Author: Pode Team + License: MIT License +#> +try { + $ScriptPath = (Split-Path -Parent -Path $MyInvocation.MyCommand.Path) + $podePath = Split-Path -Parent -Path $ScriptPath + if (Test-Path -Path "$($podePath)/src/Pode.psm1" -PathType Leaf) { + Import-Module "$($podePath)/src/Pode.psm1" -Force -ErrorAction Stop + } + else { + Import-Module -Name 'Pode' -MaximumVersion 2.99 -ErrorAction Stop + } +} +catch { throw } + +Start-PodeServer -Threads 6 { + Add-PodeEndpoint -Address localhost -Port '8081' -Protocol 'Https' -SelfSigned + + New-PodeLoggingMethod -File -Name 'requests' | Enable-PodeRequestLogging + New-PodeLoggingMethod -File -Name 'errors' | Enable-PodeErrorLogging + + Add-PodeRoute -Method Get -Path / -ScriptBlock { + Write-PodeTextResponse -Value 'Test' + } +} \ No newline at end of file diff --git a/src/Listener/PodeHttpRequest.cs b/src/Listener/PodeHttpRequest.cs index dd5d6b091..916f34b79 100644 --- a/src/Listener/PodeHttpRequest.cs +++ b/src/Listener/PodeHttpRequest.cs @@ -412,24 +412,6 @@ public override void PartialDispose() base.PartialDispose(); } - /* public override void Dispose() - { - RawBody = default; - _body = string.Empty; - - if (BodyStream != default(MemoryStream)) - { - BodyStream.Dispose(); - } - - if (Form != default(PodeForm)) - { - Form.Dispose(); - } - - base.Dispose(); - }*/ - /// /// Dispose managed and unmanaged resources. /// diff --git a/src/Listener/PodeSignalRequest.cs b/src/Listener/PodeSignalRequest.cs index dd593d471..7e030dfd9 100644 --- a/src/Listener/PodeSignalRequest.cs +++ b/src/Listener/PodeSignalRequest.cs @@ -127,20 +127,6 @@ protected override async Task Parse(byte[] bytes, CancellationToken cancel return true; } - /* public override void Dispose() - { - // send close frame - if (!IsDisposed) - { - PodeHelpers.WriteErrorMessage($"Closing Websocket", Context.Listener, PodeLoggingLevel.Verbose, Context); - Context.Response.WriteFrame(string.Empty, PodeWsOpCode.Close).Wait(); - } - - // remove client, and dispose - Context.Listener.Signals.Remove(Signal.ClientId); - base.Dispose(); - }*/ - /// /// Dispose managed and unmanaged resources. /// diff --git a/src/Listener/PodeSmtpRequest.cs b/src/Listener/PodeSmtpRequest.cs index cb9c8b425..5259bcf21 100644 --- a/src/Listener/PodeSmtpRequest.cs +++ b/src/Listener/PodeSmtpRequest.cs @@ -50,7 +50,7 @@ public PodeSmtpRequest(Socket socket, PodeSocket podeSocket, PodeContext context Type = PodeProtocolType.Smtp; } - private bool IsCommand(string content, string command) + private static bool IsCommand(string content, string command) { if (string.IsNullOrWhiteSpace(content)) { @@ -291,7 +291,7 @@ public void Reset() Attachments = new List(); } - private string ParseEmail(string value) + private static string ParseEmail(string value) { var parts = value.Split(':'); if (parts.Length > 1) @@ -364,7 +364,7 @@ private Hashtable ParseHeaders(string value) return headers; } - private bool IsBodyValid(string value) + private static bool IsBodyValid(string value) { var lines = value.Split(new string[] { PodeHelpers.NEW_LINE }, StringSplitOptions.None); return Array.LastIndexOf(lines, ".") > -1; @@ -423,7 +423,7 @@ private void ParseBoundary() } } - private string ParseBody(string value, string boundary = null) + private static string ParseBody(string value, string boundary = null) { // split the message up var lines = value.Split(new string[] { PodeHelpers.NEW_LINE }, StringSplitOptions.None); @@ -455,7 +455,7 @@ private string ParseBody(string value, string boundary = null) return body; } - private byte[] ConvertBodyEncoding(string body, string contentEncoding) + private static byte[] ConvertBodyEncoding(string body, string contentEncoding) { switch (contentEncoding.ToLowerInvariant()) { @@ -476,7 +476,7 @@ private byte[] ConvertBodyEncoding(string body, string contentEncoding) } } - private string ConvertBodyType(byte[] bytes, string contentType) + private static string ConvertBodyType(byte[] bytes, string contentType) { if (bytes == default(byte[]) || bytes.Length == 0) { @@ -516,22 +516,6 @@ private string ConvertBodyType(byte[] bytes, string contentType) } } - /* public override void Dispose() - { - RawBody = default; - Body = string.Empty; - - if (Attachments != default(List)) - { - foreach (var attachment in Attachments) - { - attachment.Dispose(); - } - } - - base.Dispose(); - }*/ - /// /// Dispose managed and unmanaged resources. /// diff --git a/src/Listener/PodeTcpRequest.cs b/src/Listener/PodeTcpRequest.cs index df18de9bd..847805e5a 100644 --- a/src/Listener/PodeTcpRequest.cs +++ b/src/Listener/PodeTcpRequest.cs @@ -76,13 +76,6 @@ public void Close() Context.Dispose(true); } - /* public override void Dispose() - { - RawBody = default; - _body = string.Empty; - base.Dispose(); - }*/ - /// /// Dispose managed and unmanaged resources. ///