| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Writes plain text to the HTTP response body. |
| | 4 | |
|
| | 5 | | .DESCRIPTION |
| | 6 | | Sends a raw text payload to the client and optionally sets the HTTP status |
| | 7 | | code and content type. |
| | 8 | |
|
| | 9 | | .PARAMETER InputObject |
| | 10 | | The text content to write to the response body. This can be a string or any |
| | 11 | | other object that can be converted to a string. |
| | 12 | |
|
| | 13 | | .PARAMETER StatusCode |
| | 14 | | The HTTP status code to set for the response. Defaults to 200 (OK). |
| | 15 | |
|
| | 16 | | .PARAMETER ContentType |
| | 17 | | The content type of the response. If not specified, defaults to "text/plain". |
| | 18 | |
|
| | 19 | | .EXAMPLE |
| | 20 | | Write-KrTextResponse -InputObject "Hello, World!" -StatusCode 200 |
| | 21 | | Writes "Hello, World!" to the response body with a 200 OK status code. |
| | 22 | |
|
| | 23 | | .NOTES |
| | 24 | | This function is designed to be used in the context of a Kestrun server response. |
| | 25 | | #> |
| | 26 | | function Write-KrTextResponse { |
| | 27 | | [KestrunRuntimeApi('Route')] |
| | 28 | | [CmdletBinding()] |
| | 29 | | param( |
| | 30 | | [Parameter(Mandatory = $true)] |
| | 31 | | [Alias('Text')] |
| | 32 | | [object]$InputObject, |
| | 33 | | [Parameter()] |
| | 34 | | [int]$StatusCode = 200, |
| | 35 | | [Parameter()] |
| | 36 | | [string]$ContentType |
| | 37 | | ) |
| 0 | 38 | | if ($null -ne $Context.Response) { |
| | 39 | | # Call the C# method on the $Context.Response object |
| 0 | 40 | | $Context.Response.WriteTextResponse($InputObject, $StatusCode, $ContentType) |
| | 41 | | } |
| | 42 | | } |
| | 43 | |
|