< 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@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
53%
Covered lines: 17
Uncovered lines: 15
Coverable lines: 32
Total lines: 130
Line coverage: 53.1%
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

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
 178        $Server = Resolve-KestrunServer -Server $Server
 179        if ($null -eq $Server) {
 080            throw 'Server is not initialized. Please ensure the server is configured before setting options.'
 81        }
 82    }
 83    process {
 184        $options = $Server.Options
 185        if ($null -eq $options) {
 086            throw 'Server is not initialized. Please ensure the server is configured before setting options.'
 87        }
 88
 189        if ($AllowSynchronousIO.IsPresent) {
 090            Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting ServerOptions.AllowSynchronousIO to 
 091            $options.ServerOptions.AllowSynchronousIO = $AllowSynchronousIO.IsPresent
 92        }
 193        if ($DisableResponseHeaderCompression.IsPresent) {
 094            Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting ServerOptions.AllowResponseHeaderCom
 95                -Properties $false
 096            $options.ServerOptions.AllowResponseHeaderCompression = $false
 97        }
 198        if ($DenyServerHeader.IsPresent) {
 199            Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting ServerOptions.AddServerHeader to {Ad
 1100            $options.ServerOptions.AddServerHeader = $false
 101        }
 1102        if ($AllowAlternateSchemes.IsPresent) {
 0103            Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting ServerOptions.AllowAlternateSchemes 
 0104            $options.ServerOptions.AllowAlternateSchemes = $true
 105        }
 1106        if ($AllowHostHeaderOverride.IsPresent) {
 0107            Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting ServerOptions.AllowHostHeaderOverrid
 0108            $options.ServerOptions.AllowHostHeaderOverride = $true
 109        }
 1110        if ($DisableStringReuse.IsPresent) {
 0111            Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting ServerOptions.DisableStringReuse to 
 0112            $options.ServerOptions.DisableStringReuse = $true
 113        }
 1114        if ($MaxRunspaces -gt 0) {
 0115            Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting MaxRunspaces to {MaxRunspaces}" -Pro
 0116            $options.MaxRunspaces = $MaxRunspaces
 117        }
 1118        if ($MinRunspaces -gt 0) {
 1119            Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting MinRunspaces to {MinRunspaces}" -Pro
 1120            $options.MinRunspaces = $MinRunspaces
 121        }
 122
 1123        if ($PassThru.IsPresent) {
 124            # if the PassThru switch is specified, return the server instance
 125            # Return the modified server instance
 0126            return $Server
 127        }
 128    }
 129}
 130

Methods/Properties

Set-KrServerOptions()