< Summary - Kestrun — Combined Coverage

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

Metrics

File(s)

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

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Writes CSV data to the HTTP response body.
 4    .DESCRIPTION
 5        Sends a raw CSV payload to the client and optionally sets the HTTP status
 6        code and content type.
 7    .PARAMETER InputObject
 8        The CSV content to write to the response body. This can be a string or any
 9        other object that can be converted to a string.
 10    .PARAMETER StatusCode
 11        The HTTP status code to set for the response. Defaults to 200 (OK).
 12    .PARAMETER ContentType
 13        The content type of the response. If not specified, defaults to "text/csv".
 14    .PARAMETER Delimiter
 15        The character to use as the delimiter in the CSV output. Defaults to a comma (`,`).
 16    .PARAMETER IncludeTypeInformation
 17        Switch to include type information in the CSV output.
 18    .PARAMETER QuoteFields
 19        An array of field names to always quote in the CSV output.
 20    .PARAMETER UseQuotes
 21        Specifies how to quote fields in the CSV output. Accepts values from the
 22        `Microsoft.PowerShell.Commands.BaseCsvWritingCommand+QuoteKind` enum.
 23    .PARAMETER NoHeader
 24        Switch to omit the header row from the CSV output.
 25    .EXAMPLE
 26        Write-KrCsvResponse -InputObject "Name,Age`nAlice,30`nBob,25" -StatusCode 200
 27        Writes the CSV data to the response body with a 200 OK status code.
 28    .NOTES
 29        This function is designed to be used in the context of a Kestrun server response.
 30#>
 31function Write-KrCsvResponse {
 32    [KestrunRuntimeApi('Route')]
 33    [CmdletBinding()]
 34    param(
 35        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 36        [object]$InputObject,
 37        [Parameter()]
 38        [int]$StatusCode = 200,
 39        [Parameter()]
 40        [string]$ContentType,
 41        [Parameter()]
 42        [char]$Delimiter,
 43        [Parameter()]
 44        [switch]$IncludeTypeInformation,
 45        [Parameter()]
 46        [string[]]$QuoteFields,
 47        [Parameter()]
 48        [Microsoft.PowerShell.Commands.BaseCsvWritingCommand+QuoteKind]$UseQuotes,
 49        [Parameter()]
 50        [switch]$NoHeader
 51    )
 52    begin {
 53        # Collect all piped items
 054        $items = @()
 055        $ContentType = [string]::IsNullOrEmpty($ContentType) ? 'text/csv' : $ContentType
 56    }
 57    process {
 58        # Accumulate; no output yet
 059        $items += $InputObject
 60    }
 61    end {
 62        # Only works inside a route script block where $Context is available
 063        if ($null -eq $Context -or $null -eq $Context.Response) {
 064            Write-KrOutsideRouteWarning
 65            return
 66        }
 67        #  - single item by default when only one was piped
 68        #  - array if multiple items were piped
 69
 070        $params = @{}
 071        if ($Delimiter) { $params['Delimiter'] = $Delimiter }
 072        if ($IncludeTypeInformation.IsPresent) { $params['IncludeTypeInformation'] = $true }
 073        if ($QuoteFields) { $params['QuoteFields'] = $QuoteFields }
 074        if ($UseQuotes) { $params['UseQuotes'] = $UseQuotes }
 075        if ($NoHeader.IsPresent) { $params['NoHeader'] = $true }
 76
 77        # Convert the payload to CSV
 078        $csv = $items | ConvertTo-Csv @params
 79        # Write the CSV response
 080        $Context.Response.WriteTextResponse($csv -join "`n", $StatusCode, $ContentType)
 81    }
 82}
 83

Methods/Properties

Write-KrCsvResponse()