| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Writes a response to the HTTP client. |
| | 4 | | .DESCRIPTION |
| | 5 | | This function is a wrapper around the Kestrun server response methods. |
| | 6 | | .PARAMETER InputObject |
| | 7 | | The input object to write to the response body. This can be a stream, byte array, or other types. |
| | 8 | | .PARAMETER StatusCode |
| | 9 | | The HTTP status code to set for the response. Defaults to 200 (OK). |
| | 10 | | .PARAMETER ContentType |
| | 11 | | The content type of the response. If not specified, defaults to "application/octet-stream". |
| | 12 | | .EXAMPLE |
| | 13 | | Write-KrResponse -InputObject $myStream -StatusCode 200 -ContentType "application/octet-stream" |
| | 14 | | Writes the $myStream to the response body with a 200 OK status code and content type "application/octet-stream". |
| | 15 | | .NOTES |
| | 16 | | This function is designed to be used in the context of a Kestrun server response. |
| | 17 | | #> |
| | 18 | | function Write-KrResponse { |
| | 19 | | [KestrunRuntimeApi('Route')] |
| | 20 | | [CmdletBinding()] |
| | 21 | | param( |
| | 22 | | [Parameter(Mandatory = $true)] |
| | 23 | | [System.IO.Stream]$InputObject, |
| | 24 | | [Parameter()] |
| | 25 | | [int]$StatusCode = 200 |
| | 26 | | ) |
| 0 | 27 | | if ($null -ne $Context.Response) { |
| | 28 | | # Call the C# method on the $Context.Response object |
| 0 | 29 | | $Context.Response.WriteResponse($InputObject, $StatusCode, $ContentType) |
| | 30 | | } |
| | 31 | | } |
| | 32 | |
|