< Summary - Kestrun — Combined Coverage

Information
Class: Public.Server.Set-KrServerLimit
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Set-KrServerLimit.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 39
Coverable lines: 39
Total lines: 165
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 08/26/2025 - 01:25:22 Line coverage: 67.8% (19/28) Total lines: 151 Tag: Kestrun/Kestrun@07f821172e5dc3657f1be7e6818f18d6721cf38a09/04/2025 - 22:37:32 Line coverage: 67.8% (19/28) Total lines: 152 Tag: Kestrun/Kestrun@afb7aadc0a8a42bfa2b51ea62c8a6e2cf63faec609/08/2025 - 20:34:03 Line coverage: 66.6% (20/30) Total lines: 156 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7209/09/2025 - 20:36:29 Line coverage: 58.5% (24/41) Total lines: 167 Tag: Kestrun/Kestrun@eec6e531f6ea893bb4939db76943e009d9fd963c10/13/2025 - 16:52:37 Line coverage: 0% (0/39) Total lines: 165 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

File(s)

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

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Configures advanced options and operational limits for a Kestrun server instance.
 4    .DESCRIPTION
 5        This function allows administrators to fine-tune the behavior of a Kestrun server by setting various
 6        operational limits and options.
 7    .PARAMETER Server
 8        The Kestrun server instance to configure.This parameter is mandatory and must be a valid server object.
 9    .PARAMETER MaxRequestBodySize
 10        Specifies the maximum allowed size of the HTTP request body in bytes.
 11        Requests exceeding this size will be rejected.
 12        Default: 30,000,000 bytes (28.6 MB).
 13    .PARAMETER MaxConcurrentConnections
 14        Sets the maximum number of concurrent client connections allowed to the server.
 15        Additional connection attempts will be queued or rejected.
 16        Default: Unlimited (no explicit limit).
 17    .PARAMETER MaxRequestHeaderCount
 18        Defines the maximum number of HTTP headers permitted in a single request.
 19        Requests with more headers will be rejected.
 20        Default: 100.
 21    .PARAMETER KeepAliveTimeoutSeconds
 22        Specifies the duration, in seconds, that a connection is kept alive when idle before being closed.
 23        Default: 120 seconds.
 24    .PARAMETER MaxRequestBufferSize
 25        Sets the maximum size, in bytes, of the buffer used for reading HTTP requests.
 26        Default: 1048576 bytes (1 MB).
 27    .PARAMETER MaxRequestHeadersTotalSize
 28        Specifies the maximum combined size, in bytes, of all HTTP request headers.
 29        Requests exceeding this size will be rejected.
 30        Default: 32768 bytes (32 KB).
 31    .PARAMETER MaxRequestLineSize
 32        Sets the maximum allowed length, in bytes, of the HTTP request line (method, URI, and version).
 33        Default: 8192 bytes (8 KB).
 34    .PARAMETER MaxResponseBufferSize
 35        Specifies the maximum size, in bytes, of the buffer used for sending HTTP responses.
 36        Default: 65536 bytes (64 KB).
 37    .PARAMETER MinRequestBodyDataRate
 38        Defines the minimum data rate, in bytes per second, required for receiving the request body.
 39        If the rate falls below this threshold, the connection may be closed.
 40        Default: 240 bytes/second.
 41    .PARAMETER MinResponseDataRate
 42        Sets the minimum data rate, in bytes per second, required for sending the response.
 43        Default: 240 bytes/second.
 44    .PARAMETER RequestHeadersTimeoutSeconds
 45        Specifies the maximum time, in seconds, allowed to receive the complete set of request headers.
 46        Default: 30 seconds.
 47    .PARAMETER PassThru
 48        If specified, the cmdlet will return the modified server instance after applying the limits.
 49    .OUTPUTS
 50        [Kestrun.Hosting.KestrunHost]
 51        The modified Kestrun server instance after applying the limits.
 52    .EXAMPLE
 53        Set-KrServerLimit -Server $server -MaxRequestBodySize 30000000
 54        Applies the specified limits to the Kestrun server instance.
 55    .EXAMPLE
 56        Set-KrServerLimit -Server $server -MinRequestBodyDataRate 240
 57        Sets the minimum data rate for receiving the request body.
 58    .EXAMPLE
 59        Set-KrServerLimit -Server $server -MaxResponseBufferSize 65536
 60        Sets the maximum size of the buffer used for sending HTTP responses.
 61    .EXAMPLE
 62        Set-KrServerLimit -Server $server -MinResponseDataRate 240
 63        Sets the minimum data rate for sending the response.
 64    .EXAMPLE
 65        Set-KrServerLimit -Server $server -MaxRequestBodySize 30000000
 66        Applies the specified limits to the Kestrun server instance.
 67    .NOTES
 68        This cmdlet modifies the server instance's configuration to enforce the specified limits.
 69#>
 70function Set-KrServerLimit {
 71    [KestrunRuntimeApi('Definition')]
 72    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
 73    [CmdletBinding()]
 74    [OutputType([Kestrun.Hosting.KestrunHost])]
 75    param(
 76        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 77        [Kestrun.Hosting.KestrunHost]$Server,
 78        [Parameter()]
 79        [long]$MaxRequestBodySize , # Default is 30,000,000
 80        [Parameter()]
 81        [int]$MaxConcurrentConnections ,
 82        [Parameter()]
 83        [int]$MaxRequestHeaderCount , # Default is 100
 84        [Parameter()]
 85        [ValidateRange(1, [int]::MaxValue)]
 86        [int]$KeepAliveTimeoutSeconds  , # Default is 130 seconds
 87        [Parameter()]
 88        [long]$MaxRequestBufferSize , #default is 1,048,576 bytes (1 MB).
 89        [Parameter()]
 90        [int]$MaxRequestHeadersTotalSize , # Default is 32,768 bytes (32 KB)
 91        [Parameter()]
 92        [int]$MaxRequestLineSize , # Default is 8,192 bytes (8 KB)
 93        [Parameter()]
 94        [long]$MaxResponseBufferSize  , # Default is  65,536 bytes (64 KB).
 95        [Parameter()]
 96        [Microsoft.AspNetCore.Server.Kestrel.Core.MinDataRate]$MinRequestBodyDataRate , # Defaults to 240 bytes/second w
 97        [Parameter()]
 98        [Microsoft.AspNetCore.Server.Kestrel.Core.MinDataRate]$MinResponseDataRate, # Defaults to 240 bytes/second with 
 99        [Parameter()]
 100        [ValidateRange(1, [int]::MaxValue)]
 101        [int]$RequestHeadersTimeoutSeconds, # Default is 30 seconds.
 102        [Parameter()]
 103        [switch]$PassThru
 104    )
 105    begin {
 106        # Ensure the server instance is resolved
 0107        $Server = Resolve-KestrunServer -Server $Server
 108    }
 109    process {
 0110        $options = $Server.Options
 0111        if ($null -eq $options) {
 0112            throw 'Server is not initialized.Please ensure the server is configured before setting limits.'
 113        }
 0114        if ($MaxRequestBodySize -gt 0) {
 0115            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MaxRequestBodySize to {MaxRequestBodySiz
 0116            $options.ServerLimits.MaxRequestBodySize = $MaxRequestBodySize
 117        }
 0118        if ($MaxConcurrentConnections -gt 0) {
 0119            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MaxConcurrentConnections to {MaxConcurre
 0120            $options.ServerLimits.MaxConcurrentConnections = $MaxConcurrentConnections
 121        }
 0122        if ($MaxRequestHeaderCount -gt 0) {
 0123            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MaxRequestHeaderCount to {MaxRequestHead
 0124            $options.ServerLimits.MaxRequestHeaderCount = $MaxRequestHeaderCount
 125        }
 0126        if ($KeepAliveTimeoutSeconds -gt 0) {
 0127            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting KeepAliveTimeout to {KeepAliveTimeoutSec
 0128            $options.ServerLimits.KeepAliveTimeout = [TimeSpan]::FromSeconds($KeepAliveTimeoutSeconds)
 129        }
 0130        if ($MaxRequestBufferSize -gt 0) {
 0131            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MaxRequestBufferSize to {MaxRequestBuffe
 0132            $options.ServerLimits.MaxRequestBufferSize = $MaxRequestBufferSize
 133        }
 0134        if ($MaxRequestHeadersTotalSize -gt 0) {
 0135            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MaxRequestHeadersTotalSize to {MaxReques
 0136            $options.ServerLimits.MaxRequestHeadersTotalSize = $MaxRequestHeadersTotalSize
 137        }
 0138        if ($MaxRequestLineSize -gt 0) {
 0139            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MaxRequestLineSize to {MaxRequestLineSiz
 0140            $options.ServerLimits.MaxRequestLineSize = $MaxRequestLineSize
 141        }
 0142        if ($MaxResponseBufferSize -gt 0) {
 0143            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MaxResponseBufferSize to {MaxResponseBuf
 0144            $options.ServerLimits.MaxResponseBufferSize = $MaxResponseBufferSize
 145        }
 0146        if ($null -ne $MinRequestBodyDataRate) {
 0147            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MinRequestBodyDataRate to {MinRequestBod
 0148            $options.ServerLimits.MinRequestBodyDataRate = $MinRequestBodyDataRate
 149        }
 0150        if ($null -ne $MinResponseDataRate) {
 0151            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting MinResponseDataRate to {MinResponseDataR
 0152            $options.ServerLimits.MinResponseDataRate = $MinResponseDataRate
 153        }
 0154        if ($null -ne $RequestHeadersTimeout) {
 0155            Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting RequestHeadersTimeout to {RequestHeaders
 0156            $options.ServerLimits.RequestHeadersTimeout = [TimeSpan]::FromSeconds($RequestHeadersTimeoutSeconds)
 157        }
 158
 0159        if ($PassThru.IsPresent) {
 160            # if the PassThru switch is specified, return the modified server instance
 0161            return $Server
 162        }
 163    }
 164}
 165

Methods/Properties

Set-KrServerLimit()