< Summary - Kestrun — Combined Coverage

Information
Class: Public.Response.Write-KrCborResponse
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Response/Write-KrCborResponse.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 50
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: 0% (0/2) Total lines: 32 Tag: Kestrun/Kestrun@07f821172e5dc3657f1be7e6818f18d6721cf38a09/04/2025 - 18:11:31 Line coverage: 0% (0/2) Total lines: 33 Tag: Kestrun/Kestrun@de99e24698289f3f61ac7b73e96092732ae12b0509/12/2025 - 03:43:11 Line coverage: 0% (0/3) Total lines: 36 Tag: Kestrun/Kestrun@d160286e3020330b1eb862d66a37db2e26fc904209/16/2025 - 16:28:42 Line coverage: 0% (0/6) Total lines: 50 Tag: Kestrun/Kestrun@d5c0d6132e97ca542441289c02a4c9e9d0364d49

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Response/Write-KrCborResponse.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Writes an object serialized as CBOR to the HTTP response.
 4    .DESCRIPTION
 5        Converts the provided object to CBOR format and writes it to the response body. The status code and content type
 6    .PARAMETER InputObject
 7        The object to serialize and write to the response.
 8    .PARAMETER StatusCode
 9        The HTTP status code to set for the response. Defaults to 200.
 10    .PARAMETER ContentType
 11        The content type to set for the response. If not specified, defaults to application/cbor
 12    .EXAMPLE
 13        Write-KrCborResponse -InputObject $myObject -StatusCode 200 -ContentType "application/cbor"
 14        Writes the $myObject serialized as CBOR to the response with a 200 status code and
 15        content type "application/cbor".
 16#>
 17function Write-KrCborResponse {
 18    [KestrunRuntimeApi('Route')]
 19    [CmdletBinding()]
 20    param(
 21        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 22        [object]$InputObject,
 23        [Parameter()]
 24        [int]$StatusCode = 200,
 25        [Parameter()]
 26        [string]$ContentType
 27    )
 28    begin {
 29        # Collect all piped items
 030        $items = [System.Collections.Generic.List[object]]::new()
 31    }
 32    process {
 33        # Accumulate; no output yet
 034        $items.Add($InputObject)
 35    }
 36    end {
 37        # Only works inside a route script block where $Context is available
 038        if ($null -eq $Context -or $null -eq $Context.Response) {
 039            Write-KrOutsideRouteWarning
 40            return
 41        }
 42        #  - single item by default when only one was piped
 43        #  - array if multiple items were piped
 044        $payload = if ($items.Count -eq 1) { $items[0] } else { $items.ToArray() }
 45
 46        # Write the CBOR response
 047        $Context.Response.WriteCborResponse($payload, $StatusCode, $ContentType)
 48    }
 49}
 50

Methods/Properties

Write-KrCborResponse()