Skip to content

Instantly share code, notes, and snippets.

@stefanschneider
Created July 18, 2016 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanschneider/072f6b88345a2d9c3269b0b957553f76 to your computer and use it in GitHub Desktop.
Save stefanschneider/072f6b88345a2d9c3269b0b957553f76 to your computer and use it in GitHub Desktop.
if (!$env:HOST ) { $env:HOST = "127.0.0.1" }
if (!$env:PORT ) { $env:PORT = "8089" }
$listener = New-Object System.Net.HttpListener
$listener.Prefixes.Add("http://${env:HOST}:${env:PORT}/")
$listener.Start()
Write-Host "Listening at $($listener.Prefixes[0]) ..."
while ($listener.IsListening)
{
$context = $listener.GetContext()
$requestUrl = $context.Request.Url
$response = $context.Response
Write-Output "> $requestUrl"
$localPath = $requestUrl.LocalPath
$buffer = [System.Text.Encoding]::UTF8.GetBytes(((gci -path env:*) | Out-String))
$response.ContentLength64 = $buffer.Length
$response.OutputStream.Write($buffer, 0, $buffer.Length)
Write-Output "< $($response.StatusCode)"
$response.Dispose()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment