HerokuHttpsRedirect

Redirect non-secure requests to HTTPS.

A request whose x-forwarded-proto header is http, and that no exclusion predicate matches, is redirected to the same path and query string, byte for byte, on https:// host. The request gets 400 Bad Request instead when its target is neither origin-form (/path?query) nor an absolute-form http:// or https:// URI (whose path and query alone are kept), or when host is not set and the request's host is not a valid host name or IP literal, or is not one of the allowedHosts when that list is not empty.

Always set host. Without it, the redirect goes to the request's host, call.request.origin.serverHost, which the client chooses: it is the Host header, or, when Ktor's XForwardedHeaders or ForwardedHeaders plugin is installed, the X-Forwarded-Host (or X-Forwarded-Server) or Forwarded: host= value, which a router that routes on Host, such as Heroku's, does not check. An application that serves several domains and so cannot set host should list them in Configuration.allowedHosts.

Throws

if the configured host is not an ASCII host name, an IPv4 address or a bracketed IPv6 literal, optionally followed by a :port from 1 to 65535, or if an allowedHosts entry is not an ASCII host name, an IPv4 address or a bracketed IPv6 literal

Constructors

Link copied to clipboard

Types

Link copied to clipboard

Redirect feature configuration

Link copied to clipboard
object Feature : Plugin<ApplicationCallPipeline, HerokuHttpsRedirect.Configuration, HerokuHttpsRedirect>

Feature installation object

Properties

Link copied to clipboard

The hosts a request may be redirected to when host is not set, as configured with Configuration.allowedHosts. Empty, the default, 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
val host: String?

HTTPS host to redirect to, or null to keep the host of the incoming request, which the client chooses (see the class documentation and allowedHosts). Set the port with redirectPort (configured as Configuration.sslPort); a :port given in the host is still accepted for compatibility.

Link copied to clipboard

If it does permanent redirect

Link copied to clipboard

HTTPS port to redirect to