| | | 1 | | using Microsoft.AspNetCore.Server.Kestrel.Core; |
| | | 2 | | using Microsoft.AspNetCore.Server.Kestrel.Https; |
| | | 3 | | using Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes; |
| | | 4 | | using Kestrun.Health; |
| | | 5 | | namespace Kestrun.Hosting.Options; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Simple options class for configuring Kestrel server settings. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// This class provides a strongly-typed alternative to using a hashtable for Kestrel server options. |
| | | 12 | | /// </remarks> |
| | | 13 | | public class KestrunOptions |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Default media type value for responses. |
| | | 17 | | /// </summary> |
| | | 18 | | private const string DefaultResponseMediaTypeValue = "text/plain"; |
| | | 19 | | /// <summary> |
| | | 20 | | /// Default media type value for API responses. |
| | | 21 | | /// </summary> |
| | | 22 | | private const string DefaultApiResponseMediaTypeValue = "application/json"; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Default upload path value for form parts. |
| | | 26 | | /// </summary> |
| | 1 | 27 | | private static readonly string DefaultUploadPathValue = Path.Combine(Path.GetTempPath(), "kestrun-uploads"); |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets or sets the Kestrel server options. |
| | | 31 | | /// </summary> |
| | 1346 | 32 | | public KestrelServerOptions ServerOptions { get; set; } |
| | | 33 | | |
| | | 34 | | /// <summary>Provides access to request limit options. Use a hashtable or a KestrelServerLimits instance.</summary> |
| | 2 | 35 | | public KestrelServerLimits ServerLimits => ServerOptions.Limits; |
| | | 36 | | |
| | | 37 | | /// <summary>Application name (optional, for diagnostics).</summary> |
| | 644 | 38 | | public string? ApplicationName { get; set; } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets or sets the maximum number of runspaces to use for script execution. |
| | | 42 | | /// </summary> |
| | 66 | 43 | | public int? MaxRunspaces { get; set; } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets or sets the minimum number of runspaces to use for script execution. |
| | | 47 | | /// Defaults to 1. |
| | | 48 | | /// </summary> |
| | 1354 | 49 | | public int MinRunspaces { get; set; } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Gets or sets the maximum number of runspaces to use for the scheduler service. |
| | | 53 | | /// Defaults to 8. |
| | | 54 | | /// </summary> |
| | 1289 | 55 | | public int MaxSchedulerRunspaces { get; set; } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets or sets the health endpoint configuration. |
| | | 59 | | /// </summary> |
| | 2572 | 60 | | public HealthEndpointOptions Health { get; set; } = new(); |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// List of configured listeners for the Kestrel server. |
| | | 64 | | /// Each listener can be configured with its own IP address, port, protocols, and other options. |
| | | 65 | | /// </summary> |
| | 295 | 66 | | public List<ListenerOptions> Listeners { get; } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Gets the HTTPS connection adapter options. |
| | | 70 | | /// </summary> |
| | 63 | 71 | | public HttpsConnectionAdapterOptions? HttpsConnectionAdapter { get; set; } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Optional path to a Unix domain socket for Kestrel to listen on. |
| | | 75 | | /// </summary> |
| | 67 | 76 | | public List<string> ListenUnixSockets { get; } |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// Optional name of a Named Pipe for Kestrel to listen on. |
| | | 80 | | /// </summary> |
| | 67 | 81 | | public List<string> NamedPipeNames { get; } |
| | | 82 | | |
| | | 83 | | /// <summary> |
| | | 84 | | /// Gets or sets the Named Pipe transport options. |
| | | 85 | | /// </summary> |
| | 65 | 86 | | public NamedPipeTransportOptions? NamedPipeOptions { get; set; } |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Gets or sets the default media type to use for responses when no Accept header is provided. |
| | | 90 | | /// </summary> |
| | 0 | 91 | | public Dictionary<string, ICollection<ContentTypeWithSchema>> DefaultResponseMediaType { get; set; } = |
| | 1282 | 92 | | new Dictionary<string, ICollection<ContentTypeWithSchema>> { { "default", new List<ContentTypeWithSchema> { new( |
| | | 93 | | |
| | | 94 | | /// <summary> |
| | | 95 | | /// Gets or sets the default media type to use for API responses when no Accept header is provided. |
| | | 96 | | /// </summary> |
| | 0 | 97 | | public Dictionary<string, ICollection<ContentTypeWithSchema>> DefaultApiResponseMediaType { get; set; } = |
| | 1282 | 98 | | new Dictionary<string, ICollection<ContentTypeWithSchema>> { { "default", new List<ContentTypeWithSchema> { new( |
| | | 99 | | |
| | | 100 | | /// <summary> |
| | | 101 | | /// Gets or sets the default upload path for form parts. |
| | | 102 | | /// </summary> |
| | 1282 | 103 | | public string DefaultUploadPath { get; set; } = DefaultUploadPathValue; |
| | | 104 | | |
| | | 105 | | /// <summary> |
| | | 106 | | /// Initializes a new instance of the <see cref="KestrunOptions"/> class with default values. |
| | | 107 | | /// </summary> |
| | 1282 | 108 | | public KestrunOptions() |
| | | 109 | | { |
| | | 110 | | // Set default values if needed |
| | 1282 | 111 | | MinRunspaces = 1; // Default to 1 runspace |
| | 1282 | 112 | | Listeners = []; |
| | 1282 | 113 | | ServerOptions = new KestrelServerOptions(); |
| | 1282 | 114 | | MaxSchedulerRunspaces = 8; // Default max scheduler runspaces |
| | 1282 | 115 | | ListenUnixSockets = []; |
| | 1282 | 116 | | NamedPipeNames = []; |
| | 1282 | 117 | | Health = new HealthEndpointOptions(); |
| | 1282 | 118 | | } |
| | | 119 | | } |