Currently I am able to get the host from the request, which includes domain and optional port. Unfortunately, it does not include the protocol (http vs https), so I cannot create absolute urls to the site itself.
object Application extends Controller {
def index = Action { request =>
Ok(request.host + "/some/path") // Returns "localhost:9000/some/path"
}
}
Is there any way to get the protocol from the request object?
Actually your portnumber will give you if it’s http or https.
Start your Play server with https support
JAVA_OPTS=-Dhttps.port=9001 play startHere’s a code snippet (you can make the validation more stable with a regex, take the https port number from properties …)
The code will return