Skip to content

Commit

Permalink
feat: HttpListenerRequest.get_Form/FormData ( Fixes #1121 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed May 4, 2024
1 parent 2dfcaf0 commit b1fda4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Types/HttpListener/Request/Alias.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@{
IP = 'IPAddress'
Form = 'FormData'
HostHeader = 'HostName'
Subdomains = 'Subdomain'
QueryParameters = 'QueryParameter'
Expand Down
31 changes: 31 additions & 0 deletions Types/HttpListener/Request/get_FormData.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<#
.SYNOPSIS
Get the form data.
.DESCRIPTION
Get the form data from the request.
.OUTPUTS
[Ordered]
.NOTES
If the content type was not application/x-www-form-urlencoded, this will return an empty dictionary.
If there was no request body, this will return an empty dictionary.
If the request body is not already cached, it will be parsed and cached.
#>
param()
if ($this.'.CachedFormData') { return $this.'.CachedFormData' }
$cachedFormData = [Ordered]@{}
if ($this.ContentType -match 'application/x-www-form-urlencoded' -and $this.Body) {
$parsedFormData = [Web.HttpUtility]::ParseQueryString($this.Body)
foreach ($key in $parsedFormData.Keys) {
$cachedFormData[$key] = $parsedFormData[$key]
}
}
$this.psobject.properties.add((
[psnoteproperty]::new('.CachedFormData', $cachedFormData)
), $true)
return $cachedFormData



0 comments on commit b1fda4d

Please sign in to comment.