< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Health.HealthEndpointOptions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Health/HealthEndpointOptions.cs
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
100%
Covered lines: 53
Uncovered lines: 0
Coverable lines: 53
Total lines: 193
Line coverage: 100%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/13/2025 - 16:52:37 Line coverage: 100% (53/53) Branch coverage: 50% (2/4) Total lines: 193 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e 10/13/2025 - 16:52:37 Line coverage: 100% (53/53) Branch coverage: 50% (2/4) Total lines: 193 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Health/HealthEndpointOptions.cs

#LineLine coverage
 1using Kestrun.Scripting;
 2
 3namespace Kestrun.Health;
 4
 5/// <summary>
 6/// Supported response content types for the built-in health endpoint.
 7/// </summary>
 8public enum HealthEndpointContentType
 9{
 10    /// <summary>
 11    /// Emits JSON output (default).
 12    /// </summary>
 13    Json,
 14    /// <summary>
 15    /// Emits YAML output.
 16    /// </summary>
 17    Yaml,
 18    /// <summary>
 19    /// Emits XML output.
 20    /// </summary>
 21    Xml,
 22    /// <summary>
 23    /// Emits a concise human-readable plain text summary.
 24    /// </summary>
 25    Text,
 26    /// <summary>
 27    /// Automatically negotiates based on the Accept header.
 28    /// </summary>
 29    Auto
 30}
 31
 32/// <summary>
 33/// Options controlling the built-in health endpoint exposed by <see cref="Hosting.KestrunHost"/>.
 34/// </summary>
 35public sealed class HealthEndpointOptions
 36{
 131537    private string _pattern = "/health";
 38
 39    /// <summary>
 40    /// Gets or sets the relative route path the endpoint is exposed on. Defaults to <c>/health</c>.
 41    /// </summary>
 42    public string Pattern
 43    {
 344        get => _pattern;
 345        set => _pattern = string.IsNullOrWhiteSpace(value)
 346            ? "/health"
 347            : (value.StartsWith('/') ? value : "/" + value);
 48    }
 49
 50    /// <summary>
 51    /// Gets or sets the default probe tags applied when a request does not provide an explicit tag filter.
 52    /// </summary>
 132053    public string[] DefaultTags { get; set; } = [];
 54
 55    /// <summary>
 56    /// Gets or sets a value indicating whether anonymous callers can hit the endpoint.
 57    /// </summary>
 132058    public bool AllowAnonymous { get; set; } = true;
 59
 60    /// <summary>
 61    /// Gets or sets a value indicating whether degraded probes should cause the endpoint to return <c>503 ServiceUnavai
 62    /// </summary>
 563    public bool TreatDegradedAsUnhealthy { get; set; }
 64
 65    /// <summary>
 66    /// Gets or sets a value indicating whether an exception should be thrown if an endpoint with the same pattern alrea
 67    /// </summary>
 568    public bool ThrowOnDuplicate { get; set; }
 69
 70    /// <summary>
 71    /// Gets or sets additional authentication schemes required for the endpoint. Leave empty to inherit the application
 72    /// </summary>
 132073    public string[] RequireSchemes { get; set; } = [];
 74
 75    /// <summary>
 76    /// Gets or sets additional authorization policies required for the endpoint.
 77    /// </summary>
 132078    public string[] RequirePolicies { get; set; } = [];
 79
 80    /// <summary>
 81    /// Gets or sets the name of a CORS policy to apply, if any.
 82    /// </summary>
 583    public string? CorsPolicyName { get; set; }
 84
 85    /// <summary>
 86    /// Gets or sets the name of an ASP.NET Core rate limiting policy to apply, if any.
 87    /// </summary>
 588    public string? RateLimitPolicyName { get; set; }
 89
 90    /// <summary>
 91    /// Gets or sets a value indicating whether the endpoint should short-circuit the rest of the pipeline.
 92    /// </summary>
 593    public bool ShortCircuit { get; set; }
 94
 95    /// <summary>
 96    /// Gets or sets the status code returned when <see cref="ShortCircuit"/> is <c>true</c>. Defaults to <c>200</c> or 
 97    /// </summary>
 598    public int? ShortCircuitStatusCode { get; set; }
 99
 100    /// <summary>
 101    /// Gets or sets the OpenAPI summary applied to the endpoint metadata.
 102    /// </summary>
 1320103    public string? OpenApiSummary { get; set; } = "Aggregate health status.";
 104
 105    /// <summary>
 106    /// Gets or sets the OpenAPI description applied to the endpoint metadata.
 107    /// </summary>
 1320108    public string? OpenApiDescription { get; set; } = "Returns the current reported state of all registered probes.";
 109
 110    /// <summary>
 111    /// Gets or sets the OpenAPI operation id applied to the endpoint metadata.
 112    /// </summary>
 1320113    public string? OpenApiOperationId { get; set; } = "GetHealth";
 114
 115    /// <summary>
 116    /// Gets or sets the OpenAPI tag list applied to the endpoint metadata.
 117    /// </summary>
 1320118    public string[] OpenApiTags { get; set; } = ["Health"];
 119
 120    /// <summary>
 121    /// Gets or sets the OpenAPI group name applied to the endpoint metadata.
 122    /// </summary>
 5123    public string? OpenApiGroupName { get; set; }
 124
 125    /// <summary>
 126    /// Gets or sets the maximum degree of parallelism used when executing probes.
 127    /// </summary>
 1320128    public int MaxDegreeOfParallelism { get; set; } = Math.Min(Environment.ProcessorCount, 4);
 129
 130    /// <summary>
 131    /// Gets or sets the timeout applied to each individual probe execution.
 132    /// </summary>
 1320133    public TimeSpan ProbeTimeout { get; set; } = TimeSpan.FromSeconds(15);
 134
 135    /// <summary>
 136    /// Gets or sets a value indicating whether the endpoint should be automatically registered when a host is created.
 137    /// </summary>
 1320138    public bool AutoRegisterEndpoint { get; set; } = true;
 139
 140    /// <summary>
 141    /// Gets or sets the script language used when generating health check probes from script. Defaults to <see cref="Sc
 142    /// </summary>
 1320143    public ScriptLanguage DefaultScriptLanguage { get; set; } = ScriptLanguage.PowerShell;
 144
 145    /// <summary>
 146    /// Gets or sets the response content type produced by the endpoint.
 147    /// </summary>
 5148    public HealthEndpointContentType ResponseContentType { get; set; } = HealthEndpointContentType.Json;
 149
 150    /// <summary>
 151    /// Gets or sets the root element name used when emitting XML output. Defaults to <c>Response</c>.
 152    /// Ignored for non-XML output types. If null or whitespace a default of <c>Response</c> is used.
 153    /// </summary>
 1317154    public string? XmlRootElementName { get; set; } = "Response";
 155
 156    /// <summary>
 157    /// Gets or sets a value indicating whether the health response should be compressed/compact when using JSON or XML.
 158    /// When <c>false</c> (default) the output is human readable (indented / pretty). When <c>true</c> the output is
 159    /// compact (no unnecessary whitespace) which can reduce payload size for large probe data sets.
 160    /// </summary>
 2161    public bool Compress { get; set; }
 162
 163    /// <summary>
 164    /// Creates a deep copy of the current instance.
 165    /// </summary>
 166    /// <returns>A cloned <see cref="HealthEndpointOptions"/> instance.</returns>
 1167    public HealthEndpointOptions Clone() => new()
 1168    {
 1169        Pattern = Pattern,
 1170        DefaultTags = [.. DefaultTags],
 1171        AllowAnonymous = AllowAnonymous,
 1172        TreatDegradedAsUnhealthy = TreatDegradedAsUnhealthy,
 1173        ThrowOnDuplicate = ThrowOnDuplicate,
 1174        RequireSchemes = [.. RequireSchemes],
 1175        RequirePolicies = [.. RequirePolicies],
 1176        CorsPolicyName = CorsPolicyName,
 1177        RateLimitPolicyName = RateLimitPolicyName,
 1178        ShortCircuit = ShortCircuit,
 1179        ShortCircuitStatusCode = ShortCircuitStatusCode,
 1180        OpenApiSummary = OpenApiSummary,
 1181        OpenApiDescription = OpenApiDescription,
 1182        OpenApiOperationId = OpenApiOperationId,
 1183        OpenApiTags = [.. OpenApiTags],
 1184        OpenApiGroupName = OpenApiGroupName,
 1185        MaxDegreeOfParallelism = MaxDegreeOfParallelism,
 1186        ProbeTimeout = ProbeTimeout,
 1187        AutoRegisterEndpoint = AutoRegisterEndpoint,
 1188        DefaultScriptLanguage = DefaultScriptLanguage,
 1189        ResponseContentType = ResponseContentType,
 1190        XmlRootElementName = XmlRootElementName,
 1191        Compress = Compress
 1192    };
 193}