diff --git a/CHANGELOG.md b/CHANGELOG.md index 276082d0..cebafb81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ### 0.3.1-SNAPSHOT (TBD) +#### Bugfixes +* Fixed the retrival of the domain from the request in the Request class in the `jpro-routing-core` module. Now `domain` +in the route is correctly matched with the request domain. ---------------------- diff --git a/jpro-routing/core-test/src/test/scala/one/jpro/platform/routing/TestRequest.scala b/jpro-routing/core-test/src/test/scala/one/jpro/platform/routing/TestRequest.scala index 5dd42e92..0c4e94a8 100644 --- a/jpro-routing/core-test/src/test/scala/one/jpro/platform/routing/TestRequest.scala +++ b/jpro-routing/core-test/src/test/scala/one/jpro/platform/routing/TestRequest.scala @@ -3,6 +3,22 @@ package one.jpro.platform.routing import org.junit.jupiter.api.Test class TestRequest { + + @Test + def domainTest(): Unit = { + assert(Request.fromString("http://localhost:8081/d").getDomain() == "localhost") + assert(Request.fromString("http://127.0.0.1:8081/d").getDomain() == "127.0.0.1") + } + + @Test + def addressTest(): Unit = { + assert(Request.fromString("http://localhost:8081/d").getProtocol() == "http") + assert(Request.fromString("http://localhost:8081/d").getDomain() == "localhost") + assert(Request.fromString("http://localhost:8081/d").getPort() == 8081) + assert(Request.fromString("http://localhost:8081/d").getPath() == "/d") + assert(Request.fromString("http://localhost:8081/d").getDirectory() == "/") + } + @Test def fromString(): Unit = { assert(Request.fromString("http://localhost:8081/d").getQueryParametersScala() == Map()) diff --git a/jpro-routing/core/src/main/scala/one/jpro/platform/routing/Request.scala b/jpro-routing/core/src/main/scala/one/jpro/platform/routing/Request.scala index b48db803..2833bf22 100644 --- a/jpro-routing/core/src/main/scala/one/jpro/platform/routing/Request.scala +++ b/jpro-routing/core/src/main/scala/one/jpro/platform/routing/Request.scala @@ -25,15 +25,12 @@ case class Request ( def getUrl(): String = url def getProtocol(): String = protocol - def getDomain(): String = directory + def getDomain(): String = domain def getPort(): Int = port def getOriginalPath(): String = origPath - def getPath(): String = path - def getDirectory(): String = directory def getQueryParameter(key: String): Option[String] = queryParameters.get(key) - def getQueryParameterOrElse(key: String, default: String): String = queryParameters.getOrElse(key, default) private lazy val immutableJavaMap: JMap[String, String] = { @@ -46,7 +43,6 @@ case class Request ( def getQueryParametersScala(): Map[String,String] = queryParameters - def resolve(path: String): String = { assert(path.startsWith("/") || path.startsWith("./") || path.startsWith("../"), s"Path must start with / or ./ or ../ but was: ${path}")