Skip to content

Commit

Permalink
Fixed the retrival of the domain from the request in the Request clas…
Browse files Browse the repository at this point in the history
…s in the `jpro-routing-core` module
  • Loading branch information
besidev committed May 14, 2024
1 parent c473999 commit 69cc645
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

----------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand All @@ -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}")

Expand Down

0 comments on commit 69cc645

Please sign in to comment.