Skip to content

Commit

Permalink
Revert: Move RequestImpl back to where it came from
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurz committed Feb 18, 2023
1 parent 050a337 commit e558ed5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 136 deletions.
68 changes: 0 additions & 68 deletions core/play/src/main/scala-2/play/core/j/RequestImpl.scala

This file was deleted.

68 changes: 0 additions & 68 deletions core/play/src/main/scala-3/play/core/j/RequestImpl.scala

This file was deleted.

38 changes: 38 additions & 0 deletions core/play/src/main/scala/play/core/j/JavaHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,41 @@ class RequestHeaderImpl(header: RequestHeader) extends JRequestHeader {

override lazy val headers: Http.Headers = header.headers.asJava
}

/**
* trait needed as workaround for https://github.com/scala/bug/issues/11944
* Also see original pull request: https://github.com/playframework/playframework/pull/10199
* sealed so that lack of implementation can't be accidentally used elsewhere
*/
private[j] sealed trait RequestImplHelper extends JRequest {
override def addAttrs(entries: TypedEntry[_]*): JRequest = ???
}

class RequestImpl(request: Request[RequestBody]) extends RequestHeaderImpl(request) with RequestImplHelper {
override def asScala: Request[RequestBody] = request

override def attrs: TypedMap = new TypedMap(asScala.attrs)
override def withAttrs(newAttrs: TypedMap): JRequest = new JRequestImpl(request.withAttrs(newAttrs.asScala))
override def addAttr[A](key: TypedKey[A], value: A): JRequest = withAttrs(attrs.put(key, value))
override def addAttrs(e1: TypedEntry[_]): JRequest = withAttrs(attrs.putAll(e1))
override def addAttrs(e1: TypedEntry[_], e2: TypedEntry[_]): JRequest = withAttrs(attrs.putAll(e1, e2))
override def addAttrs(e1: TypedEntry[_], e2: TypedEntry[_], e3: TypedEntry[_]): JRequest =
withAttrs(attrs.putAll(e1, e2, e3))
override def addAttrs(entries: TypedEntry[_]*): JRequest = withAttrs(attrs.putAll(entries: _*))
override def addAttrs(entries: util.List[TypedEntry[_]]): JRequest = withAttrs(attrs.putAll(entries))
override def removeAttr(key: TypedKey[_]): JRequest = withAttrs(attrs.remove(key))

override def body: RequestBody = request.body
override def hasBody: Boolean = request.hasBody
override def withBody(body: RequestBody): JRequest = new JRequestImpl(request.withBody(body))

override def withTransientLang(lang: play.i18n.Lang): JRequest =
addAttr(i18n.Messages.Attrs.CurrentLang, lang)
@deprecated
override def withTransientLang(code: String): JRequest =
withTransientLang(play.i18n.Lang.forCode(code))
override def withTransientLang(locale: Locale): JRequest =
withTransientLang(new play.i18n.Lang(locale))
override def withoutTransientLang(): JRequest =
removeAttr(i18n.Messages.Attrs.CurrentLang)
}

0 comments on commit e558ed5

Please sign in to comment.