From 9b8ebbfad73c0a053a9a5a2384cd9502977bef5a Mon Sep 17 00:00:00 2001 From: Benjamin Thuillier Date: Tue, 14 Jan 2014 10:41:38 +0100 Subject: [PATCH] = routing: change internal behaviour of `host` with regex function --- .../scala/spray/routing/directives/HostDirectives.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spray-routing/src/main/scala/spray/routing/directives/HostDirectives.scala b/spray-routing/src/main/scala/spray/routing/directives/HostDirectives.scala index b5ba955e09..1f485c4926 100644 --- a/spray-routing/src/main/scala/spray/routing/directives/HostDirectives.scala +++ b/spray-routing/src/main/scala/spray/routing/directives/HostDirectives.scala @@ -48,11 +48,14 @@ trait HostDirectives { */ def host(regex: Regex): Directive1[String] = { def forFunc(regexMatch: String ⇒ Option[String]): Directive1[String] = { - hostName.map(regexMatch).flatMap { - case Some(matched) ⇒ provide(matched) - case None ⇒ reject + hostName.flatMap { name ⇒ + regexMatch(name) match { + case Some(matched) ⇒ provide(matched) + case None ⇒ reject + } } } + regex.groupCount match { case 0 ⇒ forFunc(regex.findPrefixOf(_)) case 1 ⇒ forFunc(regex.findPrefixMatchOf(_).map(_.group(1)))