Skip to content

Instantly share code, notes, and snippets.

@tdrozdowski
Last active August 27, 2015 03:54
Show Gist options
  • Save tdrozdowski/5efce0c186f2ae5ea194 to your computer and use it in GitHub Desktop.
Save tdrozdowski/5efce0c186f2ae5ea194 to your computer and use it in GitHub Desktop.
Custom Directive using existing Directive
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