Configuration

Redirect feature configuration

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The hosts a request may be redirected to when host is not set: ASCII host names, IPv4 addresses or bracketed IPv6 literals, with no port. A request whose host (compared case-insensitively, ignoring a trailing dot) is not listed gets 400 Bad Request; one that is listed is redirected to its own host. Defaults to empty, which allows any valid request host. Ignored when host is set.

Link copied to clipboard

The list of call predicates for redirect exclusion. Any call matching any of the predicates will not be redirected by this feature.

Link copied to clipboard
var host: String?

HTTPS host to redirect to: an ASCII host name, an IPv4 address or a bracketed IPv6 literal. Set the port with sslPort; a :port (1 to 65535) appended to the host is still accepted for compatibility, and is then used as given, so leave sslPort at its default when doing that. Defaults to null, which keeps the host of the incoming request, call.request.origin.serverHost: the client's Host header, or its X-Forwarded-Host, X-Forwarded-Server or Forwarded: host= value when Ktor's XForwardedHeaders or ForwardedHeaders plugin is installed. A router that routes on Host, such as Heroku's, does not check those headers, so always set it, or, for an application that serves several domains, set allowedHosts.

Link copied to clipboard

Use permanent redirect or temporary

Link copied to clipboard

HTTPS port (443 by default) to redirect to

Functions

Link copied to clipboard
fun exclude(predicate: (call: ApplicationCall) -> Boolean)

Exclude calls matching the predicate from being redirected to https by this feature. The predicate gets the call as the engine built it: on Ktor CIO, call.request.path() of an absolute-form request target (GET http://host/path) still holds the scheme and authority, unlike the path excludePrefix and excludeSuffix match.

Link copied to clipboard
fun excludePrefix(pathPrefix: String)

Exclude calls whose path (not including the query string) starts with pathPrefix from being redirected to https by this feature. The path of an absolute-form request target (GET http://host/health) is its own path (/health), so such a call is excluded exactly when the origin-form request would be.

Link copied to clipboard
fun excludeSuffix(pathSuffix: String)

Exclude calls whose path (not including the query string) ends with pathSuffix from being redirected to https by this feature. The path of an absolute-form request target (GET http://host/robots.txt) is its own path (/robots.txt), so such a call is excluded exactly when the origin-form request would be.