| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Writes an object serialized as XML to the HTTP response. |
| | 4 | |
|
| | 5 | | .DESCRIPTION |
| | 6 | | Converts the provided object to XML and writes it to the response body. The |
| | 7 | | status code and content type can be customized. |
| | 8 | | .PARAMETER InputObject |
| | 9 | | The object to serialize and write to the response body. This can be any |
| | 10 | | PowerShell object, including complex types. |
| | 11 | | .PARAMETER StatusCode |
| | 12 | | The HTTP status code to set for the response. Defaults to 200 (OK). |
| | 13 | | .PARAMETER ContentType |
| | 14 | | The content type of the response. If not specified, defaults to "application/xml". |
| | 15 | | .EXAMPLE |
| | 16 | | Write-KrXmlResponse -InputObject $myObject -StatusCode 200 -ContentType "application/kestrun-xml" |
| | 17 | | Writes the $myObject serialized as XML (<kestrun-xml>) to the response with a 200 status code |
| | 18 | | and content type "application/kestrun-xml". |
| | 19 | | .NOTES |
| | 20 | | This function is designed to be used in the context of a Kestrun server response. |
| | 21 | | #> |
| | 22 | | function Write-KrXmlResponse { |
| | 23 | | [KestrunRuntimeApi('Route')] |
| | 24 | | [CmdletBinding()] |
| | 25 | | param( |
| | 26 | | [Parameter(Mandatory = $true)] |
| | 27 | | [object]$InputObject, |
| | 28 | | [Parameter()] |
| | 29 | | [int]$StatusCode = 200, |
| | 30 | | [Parameter()] |
| | 31 | | [string]$ContentType |
| | 32 | | ) |
| 0 | 33 | | if ($null -ne $Context.Response) { |
| | 34 | | # Call the C# method on the $Context.Response object |
| 0 | 35 | | $Context.Response.WriteXmlResponse($InputObject, $StatusCode, $ContentType) |
| | 36 | | } |
| | 37 | | } |
| | 38 | |
|