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 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 22 additions & 11 deletions src/Listener/PodeHttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,22 +412,33 @@ 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 (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 != null)
{
BodyStream.Dispose();
BodyStream = null;
}

if (Form != null)
{
Form.Dispose();
Form = null;
}
mdaneri marked this conversation as resolved.
Show resolved Hide resolved
}

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