< 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@eeafbe813231ed23417e7b339e170e307b2c86f9
Line coverage
0%
Covered lines: 0
Uncovered lines: 31
Coverable lines: 31
Total lines: 127
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/12/2025 - 13:32:05 Line coverage: 53.1% (17/32) Total lines: 130 Tag: Kestrun/Kestrun@63ea5841fe73fd164406accba17a956e8c08357f10/13/2025 - 16:52:37 Line coverage: 0% (0/30) Total lines: 126 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e02/05/2026 - 00:28:18 Line coverage: 0% (0/31) Total lines: 127 Tag: Kestrun/Kestrun@d9261bd752e45afa789d10bc0c82b7d5724d9589

Coverage delta

Coverage delta 54 -54

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 AllowSynchronousIO
 10        If set to $true, allows synchronous IO operations on the server.
 11        Synchronous IO can impact scalability and is generally discouraged.
 12        Default: $false.
 13    .PARAMETER DisableResponseHeaderCompression
 14        If set to $true, disables compression of HTTP response headers.
 15        Default: $false.
 16    .PARAMETER DenyServerHeader
 17        If set to $true, removes the 'Server' HTTP header from responses for improved privacy and security.
 18        Default: $false.
 19    .PARAMETER AllowAlternateSchemes
 20        If set to $true, allows alternate URI schemes (other than HTTP/HTTPS) in requests.
 21        Default: $false.
 22    .PARAMETER AllowHostHeaderOverride
 23        If set to $true, permits overriding the Host header in incoming requests.
 24        Default: $false.
 25    .PARAMETER DisableStringReuse
 26        If set to $true, disables internal string reuse optimizations, which may increase memory usage but can help with
 27        Default: $false.
 28    .PARAMETER MaxRunspaces
 29        Specifies the maximum number of runspaces to use for script execution.
 30        This can help control resource usage and concurrency in script execution.
 31        Default: 2x CPU cores or as specified in the KestrunOptions.
 32    .PARAMETER MinRunspaces
 33        Specifies the minimum number of runspaces to use for script execution.
 34        This ensures that at least a certain number of runspaces are always available for processing requests.
 35        Default: 1.
 36    .PARAMETER DefaultUploadPath
 37        Specifies the default file system path where uploaded files will be stored.
 38        This path is used when no specific upload path is defined in form options.
 39        Default: System temporary directory (e.g., C:\Windows\Temp\kestrun-uploads).
 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()]
 56        [switch]$AllowSynchronousIO,
 57
 58        [Parameter()]
 59        [switch]$DisableResponseHeaderCompression,
 60
 61        [Parameter()]
 62        [switch]$DenyServerHeader,
 63
 64        [Parameter()]
 65        [switch]$AllowAlternateSchemes,
 66
 67        [Parameter()]
 68        [switch]$AllowHostHeaderOverride,
 69
 70        [Parameter()]
 71        [switch]$DisableStringReuse,
 72
 73        [Parameter()]
 74        [int]$MaxRunspaces,
 75
 76        [Parameter()]
 77        [int]$MinRunspaces = 1,
 78
 79        [Parameter()]
 80        [string]$DefaultUploadPath
 81    )
 82    # Ensure the server instance is resolved
 083    $Server = Resolve-KestrunServer
 84
 085    $options = $Server.Options
 086    if ($null -eq $options) {
 087        throw 'Server is not initialized. Please ensure the server is configured before setting options.'
 88    }
 89
 090    if ($AllowSynchronousIO.IsPresent) {
 091        Write-KrLog -Logger $Server.Logger -Level Verbose -Message 'Setting ServerOptions.AllowSynchronousIO to {AllowSy
 092        $options.ServerOptions.AllowSynchronousIO = $AllowSynchronousIO.IsPresent
 93    }
 094    if ($DisableResponseHeaderCompression.IsPresent) {
 095        Write-KrLog -Logger $Server.Logger -Level Verbose -Message 'Setting ServerOptions.AllowResponseHeaderCompression
 96            -Values $false
 097        $options.ServerOptions.AllowResponseHeaderCompression = $false
 98    }
 099    if ($DenyServerHeader.IsPresent) {
 0100        Write-KrLog -Logger $Server.Logger -Level Verbose -Message 'Setting ServerOptions.AddServerHeader to {AddServerH
 0101        $options.ServerOptions.AddServerHeader = $false
 102    }
 0103    if ($AllowAlternateSchemes.IsPresent) {
 0104        Write-KrLog -Logger $Server.Logger -Level Verbose -Message 'Setting ServerOptions.AllowAlternateSchemes to {Allo
 0105        $options.ServerOptions.AllowAlternateSchemes = $true
 106    }
 0107    if ($AllowHostHeaderOverride.IsPresent) {
 0108        Write-KrLog -Logger $Server.Logger -Level Verbose -Message 'Setting ServerOptions.AllowHostHeaderOverride to {Al
 0109        $options.ServerOptions.AllowHostHeaderOverride = $true
 110    }
 0111    if ($DisableStringReuse.IsPresent) {
 0112        Write-KrLog -Logger $Server.Logger -Level Verbose -Message 'Setting ServerOptions.DisableStringReuse to {Disable
 0113        $options.ServerOptions.DisableStringReuse = $true
 114    }
 0115    if ($MaxRunspaces -gt 0) {
 0116        Write-KrLog -Logger $Server.Logger -Level Verbose -Message 'Setting MaxRunspaces to {MaxRunspaces}' -Values $Max
 0117        $options.MaxRunspaces = $MaxRunspaces
 118    }
 0119    if ($MinRunspaces -gt 0) {
 0120        Write-KrLog -Logger $Server.Logger -Level Verbose -Message 'Setting MinRunspaces to {MinRunspaces}' -Values $Min
 0121        $options.MinRunspaces = $MinRunspaces
 122    }
 0123    if ($PSBoundParameters.ContainsKey('DefaultUploadPath')) {
 0124        Write-KrLog -Logger $Server.Logger -Level Verbose -Message 'Setting DefaultUploadPath to {DefaultUploadPath}' -V
 0125        $options.DefaultUploadPath = $DefaultUploadPath
 126    }
 127}

Methods/Properties

Set-KrServerOptions()