Last active
August 27, 2015 03:54
-
-
Save tdrozdowski/5efce0c186f2ae5ea194 to your computer and use it in GitHub Desktop.
Custom Directive using existing Directive
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
val filterClientIp : Directive1[InetAddress] = { | |
extractClientIP { | |
ip => | |
ip.getAddress().fold(reject){ | |
address => | |
if (address.isAnyLocalAddress) { | |
provide(address) | |
} else { | |
reject(SuspectIpRejection(address, "IP is suspect!")) | |
} | |
} | |
} | |
} | |
case class SuspectIpRejection(address: InetAddress, message : String) extends Rejection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment