< Summary - Kestrun — Combined Coverage

Information
Class: Public.Response.Write-KrBsonResponse
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Response/Write-KrBsonResponse.ps1
Tag: Kestrun/Kestrun@5f1d2b981c9d7292c11fd448428c6ab6c811c5de
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 51
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 11/19/2025 - 17:40:50 Line coverage: 0% (0/6) Total lines: 51 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd026

Metrics

File(s)

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

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Writes an object serialized as BSON to the HTTP response.
 4    .DESCRIPTION
 5        Converts the provided object to BSON 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/bson.
 12    .EXAMPLE
 13        Write-KrBsonResponse -InputObject $myObject -StatusCode 200 -ContentType "application/bson"
 14        Writes the $myObject serialized as BSON to the response with a 200 status code and content type "application/bso
 15    .NOTES
 16        This function is designed to be used in the context of a Kestrun server response.
 17#>
 18function Write-KrBsonResponse {
 19    [KestrunRuntimeApi('Route')]
 20    [CmdletBinding()]
 21    param(
 22        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 23        [object]$InputObject,
 24        [Parameter()]
 25        [int]$StatusCode = 200,
 26        [Parameter()]
 27        [string]$ContentType
 28    )
 29    begin {
 30        # Collect all piped items
 031        $items = [System.Collections.Generic.List[object]]::new()
 32    }
 33    process {
 34        # Accumulate; no output yet
 035        $items.Add($InputObject)
 36    }
 37    end {
 38        # Only works inside a route script block where $Context is available
 039        if ($null -eq $Context -or $null -eq $Context.Response) {
 040            Write-KrOutsideRouteWarning
 41            return
 42        }
 43        #  - single item by default when only one was piped
 44        #  - array if multiple items were piped
 045        $payload = if ($items.Count -eq 1) { $items[0] } else { $items.ToArray() }
 46
 47        # Write the CBOR response
 048        $Context.Response.WriteBsonResponse($payload, $StatusCode, $ContentType)
 49    }
 50}
 51

Methods/Properties

Write-KrBsonResponse()