Share via


KestrelServerOptions Class

Definition

Provides programmatic configuration of Kestrel-specific features.

public ref class KestrelServerOptions
public class KestrelServerOptions
type KestrelServerOptions = class
Public Class KestrelServerOptions
Inheritance
KestrelServerOptions

Constructors

KestrelServerOptions()

Properties

AddServerHeader

Gets or sets whether the Server header should be included in each response.

AllowAlternateSchemes

Gets or sets a value that controls how the :scheme field for HTTP/2 and HTTP/3 requests is validated.

If false then the `:scheme` field for HTTP/2 and HTTP/3 requests must exactly match the transport (e.g. https for TLS connections, http for non-TLS). If true then the `:scheme` field for HTTP/2 and HTTP/3 requests can be set to alternate values and this will be reflected by `HttpRequest.Scheme`. The Scheme must still be valid according to https://datatracker.ietf.org/doc/html/rfc3986/#section-3.1. Only enable this when working with a trusted proxy. This can be used in scenarios such as proxies converting from alternate protocols. See https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3. Applications that enable this should validate an expected scheme is provided before using it.

AllowHostHeaderOverride

In HTTP/1.x, when a request target is in absolute-form (see RFC 9112 Section 3.2.2), for example

GET http://www.example.com/path/to/index.html HTTP/1.1

the Host header is redundant. In fact, the RFC says

When an origin server receives a request with an absolute-form of request-target, the origin server MUST ignore the received Host header field (if any) and instead use the host information of the request-target.

However, it is still sensible to check whether the request target and Host header match because a mismatch might indicate, for example, a spoofing attempt. Setting this property to true bypasses that check and unconditionally overwrites the Host header with the value from the request target.

AllowResponseHeaderCompression

Gets or sets a value that controls whether dynamic compression of response headers is allowed. For more information about the security considerations of HPack dynamic header compression, visit https://tools.ietf.org/html/rfc7541#section-7.

AllowSynchronousIO

Gets or sets a value that controls whether synchronous IO is allowed for the Request and Response

ApplicationSchedulingMode

Gets or sets a value that determines how Kestrel should schedule user callbacks.

ApplicationServices

Enables the Listen options callback to resolve and use services registered by the application during startup. Typically initialized by UseKestrel().

ConfigurationLoader

Provides a configuration source where endpoints will be loaded from on server start. The default is null.

DisableStringReuse

Gets or sets a value that controls whether the string values materialized will be reused across requests; if they match, or if the strings will always be reallocated.

EnableAltSvc
Obsolete.

Controls whether to return the "Alt-Svc" header from an HTTP/2 or lower response for HTTP/3.

Limits

Provides access to request limit options.

RequestHeaderEncodingSelector

Gets or sets a callback that returns the Encoding to decode the value for the specified request header name, or null to use the default UTF8Encoding.

ResponseHeaderEncodingSelector

Gets or sets a callback that returns the Encoding to encode the value for the specified response header or trailer name, or null to use the default ASCIIEncoding.

Methods

Configure()

Creates a configuration loader for setting up Kestrel.

Configure(IConfiguration, Boolean)

Creates a configuration loader for setting up Kestrel that takes an IConfiguration as input. This configuration must be scoped to the configuration section for Kestrel.

Configure(IConfiguration)

Creates a configuration loader for setting up Kestrel that takes an IConfiguration as input. This configuration must be scoped to the configuration section for Kestrel. Call Configure(IConfiguration, Boolean) to enable dynamic endpoint binding updates.

ConfigureEndpointDefaults(Action<ListenOptions>)

Specifies a configuration Action to run for each newly created endpoint. Calling this again will replace the prior action.

ConfigureHttpsDefaults(Action<HttpsConnectionAdapterOptions>)

Specifies a configuration Action to run for each newly created https endpoint. Calling this again will replace the prior action.

Listen(EndPoint, Action<ListenOptions>)

Bind to the given endpoint. The callback configures endpoint-specific settings.

Listen(EndPoint)

Bind to the given endpoint.

Listen(IPAddress, Int32, Action<ListenOptions>)

Bind to the given IP address and port. The callback configures endpoint-specific settings.

Listen(IPAddress, Int32)

Bind to the given IP address and port.

Listen(IPEndPoint, Action<ListenOptions>)

Bind to the given IP address and port. The callback configures endpoint-specific settings.

Listen(IPEndPoint)

Bind to the given IP endpoint.

ListenAnyIP(Int32, Action<ListenOptions>)

Listens on all IPs using IPv6 [::], or IPv4 0.0.0.0 if IPv6 is not supported.

ListenAnyIP(Int32)

Listens on all IPs using IPv6 [::], or IPv4 0.0.0.0 if IPv6 is not supported.

ListenHandle(UInt64, Action<ListenOptions>)

Open a socket file descriptor. The callback configures endpoint-specific settings.

ListenHandle(UInt64)

Open a socket file descriptor.

ListenLocalhost(Int32, Action<ListenOptions>)

Listens on ::1 and 127.0.0.1 with the given port. Requesting a dynamic port by specifying 0 is not supported for this type of endpoint.

ListenLocalhost(Int32)

Listens on ::1 and 127.0.0.1 with the given port. Requesting a dynamic port by specifying 0 is not supported for this type of endpoint.

ListenNamedPipe(String, Action<ListenOptions>)

Bind to the given named pipe. Specify callback to configure endpoint-specific settings.

ListenNamedPipe(String)

Bind to the given named pipe.

ListenUnixSocket(String, Action<ListenOptions>)

Bind to the given Unix domain socket path. Specify callback to configure endpoint-specific settings.

ListenUnixSocket(String)

Bind to the given Unix domain socket path.

Extension Methods

UseSystemd(KestrelServerOptions, Action<ListenOptions>)

Open file descriptors (starting from SD_LISTEN_FDS_START) initialized by systemd socket-based activation logic if available. Specify callback to configure endpoint-specific settings.

UseSystemd(KestrelServerOptions)

Open file descriptors (starting from SD_LISTEN_FDS_START) initialized by systemd socket-based activation logic if available.

Applies to