Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request.Cookies should not have the same class as Result.Cookies #8202

Open
mariussoutier opened this issue Jan 29, 2018 · 1 comment
Open
Labels
type:breaks-compatibility Tag issues and pull requests that needs to break binary compatibility

Comments

@mariussoutier
Copy link
Contributor

Request cookies and response cookies are implemented using the same class, play.api.mvc.Cookie. So the following would compile:

Ok.withCookies(request.cookies:_*)

However it would set all request cookies to HTTP-only and remove all other settings.

So there should be two different Cookie classes, RequestCookie(name, value), and Cookie should be renamed to ResponseCookie (or SetCookie).

@mariussoutier
Copy link
Contributor Author

mariussoutier commented Jan 29, 2018

This is what I currently use to avoid the issue:

/**
  * Encapsulates a cookie that is coming from the client with a request and only contains the name and value,
  * nothing else.
  */
case class RequestCookie(name: String, value: String)

object RequestCookie {
  def fromPlayCookie(cookie: play.api.mvc.Cookie): RequestCookie =
    RequestCookie(cookie.name, cookie.value)

  /** Decode request cookies from a cookie header */
  def decodeCookieHeader(header: String): Seq[RequestCookie] =
    play.api.mvc.Cookies.decodeCookieHeader(header).map(fromPlayCookie)
}

@schmitch schmitch added the type:breaks-compatibility Tag issues and pull requests that needs to break binary compatibility label Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:breaks-compatibility Tag issues and pull requests that needs to break binary compatibility
Projects
None yet
Development

No branches or pull requests

3 participants