Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework 2.1: Scala: how to get the whole base url (including protocol)?

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?

like image 976
Eneko Alonso Avatar asked Feb 13 '13 21:02

Eneko Alonso


1 Answers

In Play 2.3 and later you can use the secure property of the Request class.

like image 125
cdmckay Avatar answered Sep 21 '22 12:09

cdmckay