< Summary - Kestrun — Combined Coverage

Information
Class: Public.Request.Get-KrRequestBody
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Request/Get-KrRequestBody.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
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

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Request/Get-KrRequestBody.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Retrieves a request body value from the HTTP request.
 4    .DESCRIPTION
 5        This function accesses the current HTTP request context and retrieves the value
 6        of the request body.
 7    .PARAMETER Raw
 8        If specified, retrieves the raw request body without any parsing.
 9    .EXAMPLE
 10        $value = Get-KrRequestBody
 11        Retrieves the value of the request body from the HTTP request.
 12    .EXAMPLE
 13        $value = Get-KrRequestBody -Raw
 14        Retrieves the raw request body from the HTTP request without any parsing.
 15    .OUTPUTS
 16        Returns the value of the request body, or $null if not found.
 17    .NOTES
 18        This function is designed to be used in the context of a Kestrun server response.
 19#>
 20function Get-KrRequestBody {
 21    [KestrunRuntimeApi('Route')]
 22    [CmdletBinding()]
 23    [OutputType([Hashtable])]
 24    param(
 25        [switch]$Raw
 26    )
 027    if ($null -ne $Context.Request) {
 028        if ($Raw) {
 29            # Get the raw request body value from the request
 030            return $Context.Request.Body
 31        }
 032        switch ($Context.Request.ContentType) {
 33            'application/json' {
 034                return $Context.Request.Body | ConvertFrom-Json -AsHashtable
 35            }
 36            'application/yaml' {
 037                return [Kestrun.Utilities.YamlHelper]::ToHashtable( $Context.Request.Body)
 38            }
 39            'application/x-www-form-urlencoded' {
 040                return $Context.Request.Form
 41            }
 42            'application/xml' {
 043                return [Kestrun.Utilities.XmlHelper]::ToHashtable( $Context.Request.Body)
 44            }
 45            default {
 046                return $Context.Request.Body
 47            }
 48        }
 49    }
 50}
 51

Methods/Properties

Get-KrRequestBody()