mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
win_uri: fixes (#35487)
* win_uri: moved away from Invoke-WebRequest and fixed multiple issues * fixes from review
This commit is contained in:
parent
63fdc3f08f
commit
a0178b79f1
9 changed files with 528 additions and 134 deletions
|
@ -1,36 +0,0 @@
|
|||
param (
|
||||
[int]$port = 8000
|
||||
)
|
||||
|
||||
$listener = New-Object Net.HttpListener
|
||||
$listener.Prefixes.Add("http://+:$port/")
|
||||
$listener.Start()
|
||||
|
||||
try {
|
||||
while ($listener.IsListening) {
|
||||
# process received request
|
||||
$context = $listener.GetContext()
|
||||
$Request = $context.Request
|
||||
$Response = $context.Response
|
||||
#$Response.Headers.Add("Content-Type","text/plain")
|
||||
|
||||
$received = '{0} {1}' -f $Request.httpmethod, $Request.url.localpath
|
||||
|
||||
# is there HTML content for this URL?
|
||||
$html = $htmlcontents[$received]
|
||||
if ($html -eq $null) {
|
||||
$Response.statuscode = 404
|
||||
$html = 'Oops, the page is not available!'
|
||||
}
|
||||
|
||||
# return the HTML to the caller
|
||||
$buffer = [Text.Encoding]::UTF8.GetBytes($html)
|
||||
$Response.ContentLength64 = $buffer.length
|
||||
$Response.OutputStream.Write($buffer, 0, $buffer.length)
|
||||
|
||||
$Response.Close()
|
||||
}
|
||||
} finally {
|
||||
$listener.Stop()
|
||||
$listener.Close()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue