< Summary - Kestrun — Combined Coverage

Information
Class: Public.Middleware.Add-KrHttpsRedirection
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Middleware/Add-KrHttpsRedirection.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 76
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/13/2025 - 16:52:37 Line coverage: 0% (0/8) Total lines: 76 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Middleware/Add-KrHttpsRedirection.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Adds HTTPS redirection middleware to the Kestrun server.
 4    .DESCRIPTION
 5        This cmdlet allows you to add HTTPS redirection middleware to a Kestrun server instance.
 6        It can be used to enforce HTTPS by redirecting HTTP requests to HTTPS.
 7    .PARAMETER Server
 8        The Kestrun server instance to which the HTTPS redirection middleware will be added.
 9    .PARAMETER Options
 10        An instance of HttpsRedirectionOptions to configure the HTTPS redirection behavior.
 11        If this parameter is provided, it takes precedence over the individual parameters.
 12    .PARAMETER RedirectStatusCode
 13        The HTTP status code to use for redirection. Default is 307 (Temporary Redirect).
 14        This parameter is ignored if the Options parameter is provided.
 15    .PARAMETER HttpsPort
 16        The HTTPS port to which requests should be redirected. If not specified, the default port (443) is used.
 17        This parameter is ignored if the Options parameter is provided.
 18    .PARAMETER PassThru
 19        If specified, the cmdlet returns the modified Kestrun server instance.
 20    .EXAMPLE
 21        Add-KrHttpsRedirection -Server $myServer -RedirectStatusCode 301 -HttpsPort 8443
 22        Adds HTTPS redirection middleware to the specified Kestrun server instance,
 23        using a 301 (Permanent Redirect) status code and redirecting to port 8443.
 24    .EXAMPLE
 25        $options = [Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionOptions]::new()
 26        $options.RedirectStatusCode = 308
 27        $options.HttpsPort = 8443
 28        Add-KrHttpsRedirection -Server $myServer -Options $options -PassThru
 29        Adds HTTPS redirection middleware to the specified Kestrun server instance,
 30        using the provided HttpsRedirectionOptions and returns the modified server instance.
 31    .NOTES
 32        This cmdlet is part of the Kestrun PowerShell module.
 33 #>
 34function Add-KrHttpsRedirection {
 35    [KestrunRuntimeApi('Definition')]
 36    [CmdletBinding(defaultParameterSetName = 'Items')]
 37    [OutputType([Kestrun.Hosting.KestrunHost])]
 38    param(
 39        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 40        [Kestrun.Hosting.KestrunHost]$Server,
 41
 42        [Parameter(Mandatory = $true, ParameterSetName = 'Options')]
 43        [Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionOptions]$Options,
 44
 45        [Parameter(ParameterSetName = 'Items')]
 46        [int]$RedirectStatusCode = [Microsoft.AspNetCore.Http.StatusCodes]::Status307TemporaryRedirect,
 47
 48        [Parameter(ParameterSetName = 'Items')]
 49        [int]$HttpsPort,
 50        [Parameter()]
 51        [switch]$PassThru
 52    )
 53    begin {
 54        # Ensure the server instance is resolved
 055        $Server = Resolve-KestrunServer -Server $Server
 56    }
 57    process {
 058        if ($PSCmdlet.ParameterSetName -eq 'Items') {
 59            # Create options from individual parameters
 060            $Options = [Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionOptions]::new()
 61            # Set default values
 062            $Options.RedirectStatusCode = $RedirectStatusCode
 63
 064            if ($PSBoundParameters.ContainsKey('HttpsPort')) { $Options.HttpsPort = $HttpsPort }
 65        }
 66
 67        # Add the HTTPS redirection middleware
 068        [Kestrun.Hosting.KestrunHttpMiddlewareExtensions]::AddHttpsRedirection($Server, $Options) | Out-Null
 69
 070        if ($PassThru.IsPresent) {
 71            # if the PassThru switch is specified, return the modified server instance
 072            return $Server
 73        }
 74    }
 75}
 76

Methods/Properties

Add-KrHttpsRedirection()