+htp #15926 Import HostDirectives from spray

This commit is contained in:
Benjamin Thuillier 2014-09-26 10:51:18 +02:00
parent 49f2e8bcf5
commit a2bcc0fb06
4 changed files with 119 additions and 3 deletions

View file

@ -0,0 +1,55 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.http.server
package directives
import akka.http.model.headers.Host
import org.scalatest.FreeSpec
class HostDirectivesSpec extends FreeSpec with GenericRoutingSpec {
"The 'host' directive" - {
"in its simple String form should" - {
"block requests to unmatched hosts" in {
Get() ~> Host("spray.io") ~> {
host("spray.com") { completeOk }
} ~> check { handled shouldEqual false }
}
"let requests to matching hosts pass" in {
Get() ~> Host("spray.io") ~> {
host("spray.com", "spray.io") { completeOk }
} ~> check { response shouldEqual Ok }
}
}
"in its simple RegEx form" - {
"block requests to unmatched hosts" in {
Get() ~> Host("spray.io") ~> {
host("hairspray.*".r) { echoComplete }
} ~> check { handled shouldEqual false }
}
"let requests to matching hosts pass and extract the full host" in {
Get() ~> Host("spray.io") ~> {
host("spra.*".r) { echoComplete }
} ~> check { responseAs[String] shouldEqual "spray.io" }
}
}
"in its group RegEx form" - {
"block requests to unmatched hosts" in {
Get() ~> Host("spray.io") ~> {
host("hairspray(.*)".r) { echoComplete }
} ~> check { handled shouldEqual false }
}
"let requests to matching hosts pass and extract the full host" in {
Get() ~> Host("spray.io") ~> {
host("spra(.*)".r) { echoComplete }
} ~> check { responseAs[String] shouldEqual "y.io" }
}
}
}
}

View file

@ -235,4 +235,4 @@ class PathDirectivesSpec extends RoutingSpec {
case None failTest("Example '" + exampleString + "' doesn't contain a test uri")
}
}
}
}