Last active
August 29, 2015 14:02
-
-
Save tkawachi/51a3daa23ea2dd27e0a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.mvc.{ RequestHeader, EssentialAction, EssentialFilter } | |
/** | |
* Apply underlying filter only when f returns true. | |
*/ | |
class FilterOnly(underlying: EssentialFilter, f: RequestHeader => Boolean) extends EssentialFilter { | |
override def apply(next: EssentialAction): EssentialAction = new EssentialAction { | |
private[this] val filteredNext = underlying(next) | |
override def apply(rh: RequestHeader) = if (f(rh)) filteredNext(rh) else next(rh) | |
} | |
} | |
object FilterOnly { | |
implicit class EssentialFilterFilterOnlyImplicit(filter: EssentialFilter) { | |
def only(f: RequestHeader => Boolean) = new FilterOnly(filter, f) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment