< Summary - Kestrun — Combined Coverage

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

Metrics

File(s)

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

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Writes plain text to the HTTP response body.
 4
 5    .DESCRIPTION
 6        Sends a raw text payload to the client and optionally sets the HTTP status
 7        code and content type.
 8
 9    .PARAMETER InputObject
 10        The text content to write to the response body. This can be a string or any
 11        other object that can be converted to a string.
 12
 13    .PARAMETER StatusCode
 14        The HTTP status code to set for the response. Defaults to 200 (OK).
 15
 16    .PARAMETER ContentType
 17        The content type of the response. If not specified, defaults to "text/plain".
 18
 19    .EXAMPLE
 20        Write-KrTextResponse -InputObject "Hello, World!" -StatusCode 200
 21        Writes "Hello, World!" to the response body with a 200 OK status code.
 22
 23    .NOTES
 24        This function is designed to be used in the context of a Kestrun server response.
 25#>
 26function Write-KrTextResponse {
 27    [KestrunRuntimeApi('Route')]
 28    [CmdletBinding()]
 29    param(
 30        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 31        [Alias('Text')]
 32        [object]$InputObject,
 33        [Parameter()]
 34        [int]$StatusCode = 200,
 35        [Parameter()]
 36        [string]$ContentType
 37    )
 38    begin {
 39        # Collect all piped items
 040        $items = [System.Collections.Generic.List[object]]::new()
 41    }
 42    process {
 43        # Accumulate; no output yet
 044        $items.Add($InputObject)
 45    }
 46    end {
 47        # Only works inside a route script block where $Context is available
 048        if ($null -eq $Context -or $null -eq $Context.Response) {
 049            Write-KrOutsideRouteWarning
 50            return
 51        }
 52        #  - single item by default when only one was piped
 53        #  - array if multiple items were piped
 054        $payload = if ($items.Count -eq 1) { $items[0] } else { $items.ToArray() }
 55
 56        # Write the CBOR response
 057        $Context.Response.WriteTextResponse($payload, $StatusCode, $ContentType)
 58    }
 59}
 60

Methods/Properties

Write-KrTextResponse()