< Summary - Kestrun — Combined Coverage

Information
Class: Public.Response.Test-KrCacheRevalidation
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Response/Test-KrCacheRevalidation.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 4
Coverable lines: 4
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 09/12/2025 - 21:57:57 Line coverage: 0% (0/2) Total lines: 52 Tag: Kestrun/Kestrun@7f3035804f966a691bd6936a199a8086730a784509/13/2025 - 17:19:56 Line coverage: 0% (0/4) Total lines: 58 Tag: Kestrun/Kestrun@ea635f1ee1937c260a89d1a43a3c203cd8767c7b09/14/2025 - 21:23:16 Line coverage: 0% (0/4) Total lines: 57 Tag: Kestrun/Kestrun@c9d2f0b3dd164d7dc0dc2407a9f006293d924223

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Response/Test-KrCacheRevalidation.ps1

#LineLine coverage
 1
 2<#
 3.SYNOPSIS
 4    Checks request validators and writes 304 if appropriate; otherwise sets ETag/Last-Modified.
 5.DESCRIPTION
 6    Returns $true if a 304 Not Modified was written (you should NOT write a body).
 7    Returns $false if cache missed; in that case the function sets validators on the response and
 8    you should write the fresh body/status yourself.
 9.PARAMETER Payload
 10    The response payload (string or byte[]) to hash for ETag generation.
 11    If you have a stable payload, use this to get automatic ETag generation.
 12    If you have a dynamic payload, consider using -ETag instead.
 13.PARAMETER ETag
 14    Explicit ETag token (quotes optional). If supplied, no hashing occurs.
 15.PARAMETER Weak
 16    Emit a weak ETag (W/"...").
 17.PARAMETER LastModified
 18    Optional last-modified timestamp to emit and validate.
 19.EXAMPLE
 20    if (-not (Test-KrCacheRevalidation -Payload $payload)) {
 21        Write-KrTextResponse -InputObject $payload -StatusCode 200
 22    } # writes auto-ETag based on payload
 23.EXAMPLE
 24    if (-not (Test-KrCacheRevalidation -ETag 'v1' -LastModified (Get-Date '2023-01-01'))) {
 25        Write-KrTextResponse -InputObject $payload -StatusCode 200
 26    } # writes explicit ETag and Last-Modified
 27#>
 28function Test-KrCacheRevalidation {
 29    [KestrunRuntimeApi('Route')]
 30    [CmdletBinding()]
 31    [OutputType([bool])]
 32    param(
 33        [Parameter(Mandatory = $true)]
 34        [object]$Payload,
 35        [Parameter()]
 36        [string]$ETag,
 37        [Parameter()]
 38        [switch]$Weak,
 39        [Parameter()]
 40        [DateTimeOffset]$LastModified
 41    )
 42
 43    # Only works inside a route script block where $Context is available
 044    if ($null -ne $Context.Response) {
 45        # Call the C# method on the $Context.Response object
 046        $handled = $Context.Response.RevalidateCache(
 47            $Payload,
 48            $ETag,
 49            $Weak.IsPresent,
 50            $LastModified
 51        )
 52
 053        return $handled
 54    } else {
 055        Write-KrOutsideRouteWarning
 56    }
 57}

Methods/Properties

Test-KrCacheRevalidation()