Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

Commit b1fa4f9

Browse files
Changes necessary for exposing the RawResponse (#147)
1 parent fb30d87 commit b1fa4f9

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/Polaris.Class.ps1

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ class Polaris {
2929
$Polaris.Listener.BeginGetContext($Polaris.ContextHandler, $Polaris)
3030

3131
[System.Net.HttpListenerRequest]$RawRequest = $Context.Request
32-
[System.Net.HttpListenerResponse]$RawResponse = $Context.Response
3332

3433
$Polaris.Log("request came in: " + $RawRequest.HttpMethod + " " + $RawRequest.RawUrl)
3534

3635
[PolarisRequest]$Request = [PolarisRequest]::new($RawRequest)
37-
[PolarisResponse]$Response = [PolarisResponse]::new()
36+
[PolarisResponse]$Response = [PolarisResponse]::new($Context.Response)
3837

3938

4039
[string]$Route = $RawRequest.Url.AbsolutePath
@@ -118,15 +117,15 @@ class Polaris {
118117
$Response.ByteResponse.CopyTo($Bytes, $LogBytes.Length)
119118
$Response.ByteResponse = $Bytes
120119
}
121-
[Polaris]::Send($RawResponse, $Response)
120+
[Polaris]::Send($Response)
122121

123122
}
124123
catch {
125124
$Polaris.Log(($_ | Out-String))
126125
$Response.SetStatusCode(500)
127126
$Response.Send($_)
128127
try{
129-
[Polaris]::Send($RawResponse, $Response)
128+
[Polaris]::Send($Response)
130129
} catch {
131130
$Polaris.Log($_)
132131
}
@@ -305,12 +304,11 @@ class Polaris {
305304
}
306305

307306
static [void] Send (
308-
[System.Net.HttpListenerResponse]$RawResponse,
309307
[PolarisResponse]$Response
310308
) {
311309
if ($Response.StreamResponse) {
312310
[Polaris]::Send(
313-
$RawResponse,
311+
$Response.RawResponse,
314312
$Response.StreamResponse,
315313
$Response.StatusCode,
316314
$Response.ContentType,
@@ -319,7 +317,7 @@ class Polaris {
319317
}
320318
else {
321319
[Polaris]::Send(
322-
$RawResponse,
320+
$Response.RawResponse,
323321
$Response.ByteResponse,
324322
$Response.StatusCode,
325323
$Response.ContentType,

lib/PolarisResponse.Class.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ class PolarisResponse {
44
[System.Net.WebHeaderCollection]$Headers = [System.Net.WebHeaderCollection]::new()
55
[int]$StatusCode = 200
66
[System.IO.Stream]$StreamResponse
7+
[System.Net.HttpListenerResponse]$RawResponse
8+
9+
PolarisResponse ([System.Net.HttpListenerResponse]$RawResponse) {
10+
$this.RawResponse = $RawResponse
11+
}
712

813
Send ([string]$stringResponse) {
914
$this.ByteResponse = [System.Text.Encoding]::UTF8.GetBytes($stringResponse)

0 commit comments

Comments
 (0)