| | | 1 | | using System.Net; |
| | | 2 | | using System.Security.Cryptography.X509Certificates; |
| | | 3 | | using Microsoft.AspNetCore.Server.Kestrel.Core; |
| | | 4 | | |
| | | 5 | | namespace Kestrun.Hosting.Options; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Configuration for an individual Kestrel listener. |
| | | 9 | | /// </summary> |
| | | 10 | | public class ListenerOptions |
| | | 11 | | { |
| | | 12 | | /// <summary>The IP address to bind to.</summary> |
| | 140 | 13 | | public IPAddress IPAddress { get; set; } |
| | | 14 | | |
| | | 15 | | /// <summary>The port to listen on.</summary> |
| | 95 | 16 | | public int Port { get; set; } |
| | | 17 | | |
| | | 18 | | /// <summary>Whether HTTPS should be used.</summary> |
| | 129 | 19 | | public bool UseHttps { get; set; } |
| | | 20 | | |
| | | 21 | | /// <summary>HTTP protocols supported by the listener.</summary> |
| | 123 | 22 | | public HttpProtocols Protocols { get; set; } |
| | | 23 | | |
| | | 24 | | /// <summary>Enable verbose connection logging.</summary> |
| | 120 | 25 | | public bool UseConnectionLogging { get; set; } |
| | | 26 | | |
| | | 27 | | /// <summary>Optional TLS certificate.</summary> |
| | 43 | 28 | | public X509Certificate2? X509Certificate { get; internal set; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets or sets a value that controls whether the "Alt-Svc" header is included with response headers. |
| | | 32 | | /// The "Alt-Svc" header is used by clients to upgrade HTTP/1.1 and HTTP/2 connections to HTTP/3. |
| | | 33 | | /// <para> |
| | | 34 | | /// The "Alt-Svc" header is automatically included with a response if <see cref="Protocols"/> has either |
| | | 35 | | /// HTTP/1.1 or HTTP/2 enabled, and HTTP/3 is enabled. If an "Alt-Svc" header value has already been set |
| | | 36 | | /// by the app then it isn't changed. |
| | | 37 | | /// </para> |
| | | 38 | | /// </summary> |
| | | 39 | | /// <remarks> |
| | | 40 | | /// Defaults to false. |
| | | 41 | | /// </remarks> |
| | 33 | 42 | | public bool DisableAltSvcHeader { get; set; } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Initializes a new instance of the <see cref="ListenerOptions"/> class with default values. |
| | | 46 | | /// </summary> |
| | 49 | 47 | | public ListenerOptions() |
| | | 48 | | { |
| | 49 | 49 | | IPAddress = IPAddress.Any; |
| | 49 | 50 | | UseHttps = false; |
| | 49 | 51 | | Protocols = HttpProtocols.Http1; |
| | 49 | 52 | | UseConnectionLogging = false; |
| | 49 | 53 | | } |
| | | 54 | | /// <summary> |
| | | 55 | | /// Returns a string representation of the listener in the format "http(s)://{IPAddress}:{Port}". |
| | | 56 | | /// </summary> |
| | | 57 | | /// <returns>A string representation of the listener.</returns> |
| | 6 | 58 | | public override string ToString() => $"{(UseHttps ? "https" : "http")}://{IPAddress}:{Port}"; |
| | | 59 | | } |