The steps involved in using route services to redirect requests to HTTPS are as follows:
You can write a small route service app to test for insecure connections and redirect to the secure endpoint when needed. An example of this app written in Go is available here. Please note this is just an example and should not be used for production.
To deploy this application, you need to cf push the application. Then create a user provided service instance which then must be bound to the application needing the redirect service. This can be done with the following three commands.
cf push http-to-https-rs-app cf create-user-provided-service http-to-https-rs -r http-to-https-rs-app.my-apps.example.com cf bind-route-service my-apps.example.com http-to-https-rs --hostname my-secure-app
For more details on the above commands, see the documentation here.
The business logic of the redirect example app requires that it test whether the original URL, obtained through the x-cf-forwarded-url
header, is secure.
It uses the x-forwarded-proto
HTTP header to make this determination. If the protocol is "https", then it passes the request to the gorouter. If not, then it returns the client a 302 redirect with the same URL, but using the secure HTTPS scheme.