Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ObjectDisposedException in PodeRequest.Receive During SSL/TLS Operations #1460

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
39 changes: 39 additions & 0 deletions examples/Web-SelfSigned.ps1
Original file line number Diff line number Diff line change
@@ -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'
}
}
33 changes: 23 additions & 10 deletions src/Listener/PodeHttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,22 +412,35 @@ public override void PartialDispose()
base.PartialDispose();
}

public override void Dispose()
/// <summary>
/// Dispose managed and unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether the method is called explicitly or by garbage collection.</param>
protected override void Dispose(bool disposing)
{
RawBody = default;
_body = string.Empty;
if (IsDisposed) return;

if (BodyStream != default(MemoryStream))
if (disposing)
{
BodyStream.Dispose();
}
// Custom cleanup logic for PodeHttpRequest
RawBody = default;
_body = string.Empty;

if (Form != default(PodeForm))
{
Form.Dispose();
if (BodyStream != default(MemoryStream))
{
BodyStream.Dispose();
BodyStream = default;
}

if (Form != default(PodeForm))
{
Form.Dispose();
Form = default;
}
}

base.Dispose();
// Call the base Dispose to clean up shared resources
base.Dispose(disposing);
}
}
}
Loading