88#>
99param (
1010# The Root Directory
11- [string ]$RootPath = $ (if ($PSScriptRoot ) {$PSScriptRoot } else { $pwd }),
11+ [Alias (' RootDirectory' )][string ]$RootPath =
12+ $ (if ($PSScriptRoot ) {$PSScriptRoot } else { $pwd }),
1213
1314# The rootUrl of the server. By default, a random loopback address.
1415[string ]$RootUrl = " http://127.0.0.1:$ ( Get-Random - Minimum 4 kb - Maximum 42 kb ) /" ,
@@ -23,11 +24,10 @@ param(
2324 " .ps1" = " text/x-powershell"
2425})
2526
26- $httpListener = [Net.HttpListener ]::new()
27- $httpListener.Prefixes.Add ($RootUrl )
27+ $httpListener = [Net.HttpListener ]::new();$httpListener.Prefixes.Add ($RootUrl )
2828Write-Warning " Listening on $RootUrl $ ( $httpListener.Start ()) "
29-
30- $io = [Ordered ]@ { # Pack our job input into an IO dictionary
29+ # Pack our job input into an IO dictionary
30+ $io = [Ordered ]@ {
3131 HttpListener = $httpListener ; ServerRoot = $RootPath
3232 Files = [Ordered ]@ {}; ContentTypes = [Ordered ]@ {}
3333}
@@ -62,14 +62,12 @@ Start-ThreadJob -ScriptBlock {param([Collections.IDictionary]$io)
6262 filter outputError ([int ]$N ) {
6363 $re.StatusCode = $N
6464 $localPath = " /$N .html" ;$file = $files [$LocalPath ]
65- if ($file ) {outputFile}
66- $re.Close ()
65+ if ($file ) {outputFile} else { $re.Close () }
6766 continue next
6867 }
6968 filter outputHeader {
7069 $re.Length = $files [$localPath ].Length
71- $re.Close ()
72- continue next
70+ $re.Close ();continue next
7371 }
7472 filter outputFile {
7573 $reply.ContentType = $contentTypes [$localPath ]
0 commit comments