HttpsRedirect
The HttpsRedirect plugin redirects all HTTP requests to the HTTPS counterpart before processing the call. By default, a resource returns 301 Moved Permanently, but it can be configured to be 302 Found.
Add dependencies
To use HttpsRedirect, you need to include the ktor-server-http-redirect artifact in the build script:
Install HttpsRedirect
To install the HttpsRedirect plugin to the application, pass it to the install function in the specified module. The code snippets below show how to install HttpsRedirect...
... inside the
embeddedServerfunction call.... inside the explicitly defined
module, which is an extension function of theApplicationclass.
The code above installs the HttpsRedirect plugin with the default configuration.
Configure HttpsRedirect
The code snippet below shows how to configure the desired HTTPS port and return 301 Moved Permanently for the requested resource:
You can find the full example here: ssl-engine-main-redirect.