Skip to content

Commit 2daab2c

Browse files
author
James Brundage
committed
feat: HttpListenerRequest get/set Module ( Fixes #1126 )
1 parent aec66fa commit 2daab2c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<#
2+
.SYNOPSIS
3+
Gets the request's module
4+
.DESCRIPTION
5+
Gets the module that is associated with the request.
6+
7+
By default, this will be any module whose `.Server` property matches the request's `.Url.DnsSafeHost` property.
8+
.NOTES
9+
This property can also be set directly, in order to serve a different loaded module.
10+
#>
11+
if ($this.'.CachedModule') { return $this.'.CachedModule' }
12+
13+
$loadedModules = @(Get-Module)
14+
$ModulesForRequest =
15+
foreach ($loadedModule in $loadedModules) {
16+
if ($loadedModule.Server -and
17+
$this.Url.DnsSafeHost -in $loadedModule.Server) {
18+
$loadedModule
19+
}
20+
}
21+
22+
$this.psobject.properties.add((
23+
[psnoteproperty]::new('.CachedModule', $ModulesForRequest)
24+
),$true)
25+
26+
return $this.'.CachedModule'
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<#
2+
.SYNOPSIS
3+
Sets the request's module
4+
.DESCRIPTION
5+
Sets the module that is associated with the request.
6+
7+
By default, this will be any module whose `.Server` property matches the request's `.Url.DnsSafeHost` property.
8+
9+
If needed, the module can be set directly, in order to serve a different loaded module.
10+
#>
11+
param(
12+
# The module to associate with the request
13+
[Parameter(Mandatory)]
14+
[Management.Automation.PSModuleInfo]$Module
15+
)
16+
17+
$this.psobject.properties.add((
18+
[psnoteproperty]::new('.CachedModule', $Module)
19+
), $true)

0 commit comments

Comments
 (0)