< 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@6135d944f8787fb570e4dfbacac6e80312799a86
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 57
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 12/01/2025 - 20:55:19 Line coverage: 0% (0/8) Total lines: 76 Tag: Kestrun/Kestrun@638a27c2dd54103f693f023b6ba5f56a884caafa05/09/2026 - 21:51:36 Line coverage: 0% (0/6) Total lines: 57 Tag: Kestrun/Kestrun@6b24c7512a1bad61723a28d32446de0aa658293e

Coverage delta

Coverage delta 1 -1

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 Options
 8        An instance of HttpsRedirectionOptions to configure the HTTPS redirection behavior.
 9        If this parameter is provided, it takes precedence over the individual parameters.
 10    .PARAMETER RedirectStatusCode
 11        The HTTP status code to use for redirection. Default is 307 (Temporary Redirect).
 12        This parameter is ignored if the Options parameter is provided.
 13    .PARAMETER HttpsPort
 14        The HTTPS port to which requests should be redirected. If not specified, the default port (443) is used.
 15        This parameter is ignored if the Options parameter is provided.
 16    .EXAMPLE
 17        Add-KrHttpsRedirection -Server $myServer -RedirectStatusCode 301 -HttpsPort 8443
 18        Adds HTTPS redirection middleware to the specified Kestrun server instance,
 19        using a 301 (Permanent Redirect) status code and redirecting to port 8443.
 20    .EXAMPLE
 21        $options = [Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionOptions]::new()
 22        $options.RedirectStatusCode = 308
 23        $options.HttpsPort = 8443
 24        Add-KrHttpsRedirection -Server $myServer -Options $options -PassThru
 25        Adds HTTPS redirection middleware to the specified Kestrun server instance,
 26        using the provided HttpsRedirectionOptions and returns the modified server instance.
 27    .NOTES
 28        This cmdlet is part of the Kestrun PowerShell module.
 29 #>
 30function Add-KrHttpsRedirection {
 31    [KestrunRuntimeApi('Definition')]
 32    [CmdletBinding(defaultParameterSetName = 'Items')]
 33    param(
 34        [Parameter(Mandatory = $true, ParameterSetName = 'Options')]
 35        [Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionOptions]$Options,
 36
 37        [Parameter(ParameterSetName = 'Items')]
 38        [int]$RedirectStatusCode = [Microsoft.AspNetCore.Http.StatusCodes]::Status307TemporaryRedirect,
 39
 40        [Parameter(ParameterSetName = 'Items')]
 41        [int]$HttpsPort
 42    )
 43    # Ensure the server instance is resolved
 044    $Server = Resolve-KestrunServer
 045    if ($PSCmdlet.ParameterSetName -eq 'Items') {
 46        # Create options from individual parameters
 047        $Options = [Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionOptions]::new()
 48        # Set default values
 049        $Options.RedirectStatusCode = $RedirectStatusCode
 50
 051        if ($PSBoundParameters.ContainsKey('HttpsPort')) { $Options.HttpsPort = $HttpsPort }
 52    }
 53
 54    # Add the HTTPS redirection middleware
 055    [Kestrun.Hosting.KestrunHttpMiddlewareExtensions]::AddHttpsRedirection($Server, $Options) | Out-Null
 56}
 57

Methods/Properties

Add-KrHttpsRedirection()