title: Playframework - Request[A] vs RequestHeader
body: <p>I'm unable to understand diffrence between <code>play.api.mvc.Request[A]</code> and <code>play.api.mvc.RequestHeader</code> and <code>play.api.mvc.Request[play.api.mvc.AnyContent]</code>. 
  <hr />
  In compiled class I've got </p>
  
  <pre><code>trait Request[+A] extends scala.AnyRef with play.api.mvc.RequestHeader {
    def $init$() : scala.Unit = { /* compiled code */ }
    def body : A
    def map[B](f : scala.Function1[A, B]) : play.api.mvc.Request[B] = { /* compiled code */ }
  }
  object Request extends scala.AnyRef {
    def apply[A](rh : play.api.mvc.RequestHeader, a : A) : scala.AnyRef with play.api.mvc.Request[A] {
    val remoteAddress : scala.Predef.String
    def username : scala.None.type
    val body : A
  } = { /* compiled code */ }
  }
  </code></pre>
  
  <h3>Request[AnyContent] ---> RequestWithUser[play.api.mvc.AnyContent] ?</h3>
  
  <pre><code>def getLoginPage[A](implicit request: Request[A], form: Form[(String, String)], msg: Option[String]): Html = {
      val req = RequestWithUser(None, request)
      views.html.secure.login(form, msg)(request = req)
    }
  </code></pre>
  
  <p>This code works in <code>TemplatePlugin</code> but it's not working in view:</p>
  
  <pre><code>@(loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)(implicit request: securesocial.core.RequestWithUser[_ &lt;: play.api.mvc.AnyContent])
  </code></pre>
  
  <p>It's not working because:</p>
  
  <pre><code>type mismatch; found : securesocial.core.RequestWithUser[A] required: securesocial.core.RequestWithUser[_ &lt;: play.api.mvc.AnyContent] 
  </code></pre>
  
  <p>So I tried to put <code>AnyContent</code> as generic type:</p>
  
  <pre><code>def getLoginPage[A](implicit request: Request[A], form: Form[(String, String)], msg: Option[String]): Html = {
      val req = RequestWithUser[play.api.mvc.AnyContent](None, request)
      views.html.secure.login(form, msg)(request = req)
    }
  </code></pre>
  
  <p>But next compilation error shown:</p>
  
  <pre><code>type mismatch; found : play.api.mvc.Request[A] required: play.api.mvc.Request[play.api.mvc.AnyContent] 
  </code></pre>
  
  <p>And play.api.mvc.AnyContent looks like:</p>
  
  <pre><code>package play.api.mvc
  sealed trait AnyContent extends scala.AnyRef {
    def $init$() : scala.Unit = { /* compiled code */ }
    def asFormUrlEncoded : scala.Option[scala.Predef.Map[scala.Predef.String, scala.Seq[scala.Predef.String]]] = { /* compiled code */ }
    def asText : scala.Option[scala.Predef.String] = { /* compiled code */ }
    def asXml : scala.Option[scala.xml.NodeSeq] = { /* compiled code */ }
    def asJson : scala.Option[play.api.libs.json.JsValue] = { /* compiled code */ }
    def asMultipartFormData : scala.Option[play.api.mvc.MultipartFormData[play.api.libs.Files.TemporaryFile]] = { /* compiled code */ }
    def asRaw : scala.Option[play.api.mvc.RawBuffer] = { /* compiled code */ }
  }
  </code></pre>
  
  <p>Please help me to solve this problem.</p>
  
  <hr />
  
  <h1>Edited - solution so far</h1>
  
  <p><hr />
  I found code that compiles and even works well. Nevertheless this is not elegant way because I used <code>asInstanceOf</code> and cast class.</p>
  
  <pre><code>def getLoginPage[A](implicit request: Request[A], form: Form[(String, String)], msg: Option[String]): Html = {
      implicit val r = RequestWithUser[play.api.mvc.AnyContent](None, request.asInstanceOf[Request[AnyContent]])
      views.html.secure.login(form, msg)(request = r)
    }
  </code></pre>