spark-ssl
spark-ssl copied to clipboard
How to redirect all HTTP request to HTTPS?
I used secure method in Spark and everything goes well. Is there any solution to redirect request which is sent via HTTP to HTTPS? ( Something like before filter that redirect request of HTTP to same url with HTTPS.)
Nothing built in, but you can create a before filter. I did the same for an app I have on Heroku:
app.before { ctx ->
if (ctx.header("x-forwarded-proto") == "http") { // heroku sets this
ctx.redirect("https://${ctx.header("host")}${ctx.path()}", 301)
}
}
If possible, I think you should avoid doing SSL in Spark, get whatever you launch it on to take care of it instead.
Unfortunately It doesn't work, after using Secure method, all filters only work with HTTPS request.
Might have to use the instance API then, and create two services. One for http and one for https, then redirect from the http to the https-one ?
I tried to create two server but because I use port 8080 for webserver, it is not possible to have two Server on same port. Why receive HTTP and HTTPS request is not possible at the same time?