< Summary - Kestrun — Combined Coverage

Information
Class: Public.Server.Set-KrServerOptions
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Set-KrServerOptions.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 126
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 09/08/2025 - 20:34:03 Line coverage: 62.5% (15/24) Total lines: 121 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7209/09/2025 - 20:36:29 Line coverage: 53.1% (17/32) Total lines: 130 Tag: Kestrun/Kestrun@eec6e531f6ea893bb4939db76943e009d9fd963c10/13/2025 - 16:52:37 Line coverage: 0% (0/30) Total lines: 126 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Set-KrServerOptions.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Configures advanced options and operational limits for a Kestrun server instance.
 4    .DESCRIPTION
 5        The Set-KrServerOptions function allows fine-grained configuration of a Kestrun server instance.
 6        It enables administrators to control server behavior, resource usage, and protocol compliance by
 7        setting limits on request sizes, connection counts, timeouts, and other operational parameters.
 8        Each parameter is optional and, if not specified, the server will use its built-in default value.
 9    .PARAMETER Server
 10        The Kestrun server instance to configure. This parameter is mandatory and must be a valid server object.
 11    .PARAMETER AllowSynchronousIO
 12        If set to $true, allows synchronous IO operations on the server.
 13        Synchronous IO can impact scalability and is generally discouraged.
 14        Default: $false.
 15    .PARAMETER DisableResponseHeaderCompression
 16        If set to $true, disables compression of HTTP response headers.
 17        Default: $false.
 18    .PARAMETER DenyServerHeader
 19        If set to $true, removes the 'Server' HTTP header from responses for improved privacy and security.
 20        Default: $false.
 21    .PARAMETER AllowAlternateSchemes
 22        If set to $true, allows alternate URI schemes (other than HTTP/HTTPS) in requests.
 23        Default: $false.
 24    .PARAMETER AllowHostHeaderOverride
 25        If set to $true, permits overriding the Host header in incoming requests.
 26        Default: $false.
 27    .PARAMETER DisableStringReuse
 28        If set to $true, disables internal string reuse optimizations, which may increase memory usage but can help with
 29        Default: $false.
 30    .PARAMETER MaxRunspaces
 31        Specifies the maximum number of runspaces to use for script execution.
 32        This can help control resource usage and concurrency in script execution.
 33        Default: 2x CPU cores or as specified in the KestrunOptions.
 34    .PARAMETER MinRunspaces
 35        Specifies the minimum number of runspaces to use for script execution.
 36        This ensures that at least a certain number of runspaces are always available for processing requests.
 37        Default: 1.
 38    .PARAMETER PassThru
 39        If specified, the cmdlet will return the modified server instance after applying the limits.
 40    .EXAMPLE
 41        Set-KrServerOptions -Server $srv -MaxRequestBodySize 1000000
 42        Configures the server instance $srv to limit request body size to 1,000,000 bytes.
 43    .EXAMPLE
 44        Set-KrServerOptions -Server $srv -AllowSynchronousIO
 45        Configures the server instance $srv to allow synchronous IO operations.
 46    .NOTES
 47        All parameters are optional except for -Server.
 48        Defaults are based on typical Kestrun server settings as of the latest release.
 49#>
 50function Set-KrServerOptions {
 51    [KestrunRuntimeApi('Definition')]
 52    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
 53    [CmdletBinding()]
 54    param(
 55        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 56        [Kestrun.Hosting.KestrunHost]$Server,
 57        [Parameter()]
 58        [switch]$AllowSynchronousIO,
 59        [Parameter()]
 60        [switch]$DisableResponseHeaderCompression ,
 61        [Parameter()]
 62        [switch]$DenyServerHeader,
 63        [Parameter()]
 64        [switch]$AllowAlternateSchemes,
 65        [Parameter()]
 66        [switch]$AllowHostHeaderOverride,
 67        [Parameter()]
 68        [switch]$DisableStringReuse,
 69        [Parameter()]
 70        [int]$MaxRunspaces,
 71        [Parameter()]
 72        [int]$MinRunspaces = 1,
 73        [Parameter()]
 74        [switch]$PassThru
 75    )
 76    begin {
 77        # Ensure the server instance is resolved
 078        $Server = Resolve-KestrunServer -Server $Server
 79    }
 80    process {
 081        $options = $Server.Options
 082        if ($null -eq $options) {
 083            throw 'Server is not initialized. Please ensure the server is configured before setting options.'
 84        }
 85
 086        if ($AllowSynchronousIO.IsPresent) {
 087            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting ServerOptions.AllowSynchronousIO to {All
 088            $options.ServerOptions.AllowSynchronousIO = $AllowSynchronousIO.IsPresent
 89        }
 090        if ($DisableResponseHeaderCompression.IsPresent) {
 091            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting ServerOptions.AllowResponseHeaderCompres
 92                -Values $false
 093            $options.ServerOptions.AllowResponseHeaderCompression = $false
 94        }
 095        if ($DenyServerHeader.IsPresent) {
 096            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting ServerOptions.AddServerHeader to {AddSer
 097            $options.ServerOptions.AddServerHeader = $false
 98        }
 099        if ($AllowAlternateSchemes.IsPresent) {
 0100            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting ServerOptions.AllowAlternateSchemes to {
 0101            $options.ServerOptions.AllowAlternateSchemes = $true
 102        }
 0103        if ($AllowHostHeaderOverride.IsPresent) {
 0104            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting ServerOptions.AllowHostHeaderOverride to
 0105            $options.ServerOptions.AllowHostHeaderOverride = $true
 106        }
 0107        if ($DisableStringReuse.IsPresent) {
 0108            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting ServerOptions.DisableStringReuse to {Dis
 0109            $options.ServerOptions.DisableStringReuse = $true
 110        }
 0111        if ($MaxRunspaces -gt 0) {
 0112            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MaxRunspaces to {MaxRunspaces}" -Values 
 0113            $options.MaxRunspaces = $MaxRunspaces
 114        }
 0115        if ($MinRunspaces -gt 0) {
 0116            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MinRunspaces to {MinRunspaces}" -Values 
 0117            $options.MinRunspaces = $MinRunspaces
 118        }
 119
 0120        if ($PassThru.IsPresent) {
 121            # if the PassThru switch is specified, return the modified server instance
 0122            return $Server
 123        }
 124    }
 125}
 126

Methods/Properties

Set-KrServerOptions()