| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Set CORS headers for a given CORS policy builder. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function sets CORS headers for a given CORS policy builder. It supports setting any header or specific headers |
| | | 6 | | .PARAMETER Builder |
| | | 7 | | The CORS policy builder to set the headers for. This parameter is mandatory and must be provided. |
| | | 8 | | .PARAMETER Any |
| | | 9 | | A switch parameter to allow any header. If this parameter is provided, the function will set the CORS policy to allo |
| | | 10 | | .PARAMETER Headers |
| | | 11 | | An array of strings representing the specific headers to allow. This parameter is mandatory when the 'Any' switch pa |
| | | 12 | | .EXAMPLE |
| | | 13 | | New-KrCorsPolicyBuilder | Set-KrCorsHeader -Any |
| | | 14 | | This example sets the CORS policy to allow any header. |
| | | 15 | | .EXAMPLE |
| | | 16 | | New-KrCorsPolicyBuilder | Set-KrCorsHeader -Headers @('Content-Type', 'Authorization') |
| | | 17 | | This example sets the CORS policy to allow specific headers ('Content-Type' and 'Authorization'). |
| | | 18 | | .OUTPUTS |
| | | 19 | | Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder |
| | | 20 | | .NOTES |
| | | 21 | | This function is part of the Kestrun PowerShell module and is used to configure CORS policies in |
| | | 22 | | #> |
| | | 23 | | function Set-KrCorsHeader { |
| | | 24 | | [KestrunRuntimeApi('Definition')] |
| | | 25 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 26 | | [CmdletBinding(DefaultParameterSetName = 'With')] |
| | | 27 | | [OutputType([Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder])] |
| | | 28 | | param( |
| | | 29 | | [Parameter(Mandatory, ValueFromPipeline)] |
| | | 30 | | [Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder]$Builder, |
| | | 31 | | |
| | | 32 | | [Parameter(Mandatory, ParameterSetName = 'Any')] |
| | | 33 | | [switch]$Any, |
| | | 34 | | |
| | | 35 | | [Parameter(Mandatory, ParameterSetName = 'With')] |
| | | 36 | | [string[]]$Headers |
| | | 37 | | ) |
| | | 38 | | process { |
| | 0 | 39 | | if ($Any) { $Builder.AllowAnyHeader() | Out-Null } |
| | 0 | 40 | | else { $Builder.WithHeaders($Headers) | Out-Null } |
| | 0 | 41 | | $Builder |
| | | 42 | | } |
| | | 43 | | } |