Skip to content

Commit 92688eb

Browse files
committed
fix: remaining path including full path
1 parent c1c8227 commit 92688eb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/main/kotlin/net/ccbluex/netty/http/rest/RouteControl.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ class RouteController : Node("") {
9696
}
9797

9898
return if (currentNode.matchesMethod(method)) {
99-
Destination(currentNode, params, pathArray.joinToString("/"))
99+
// remainingPath should only include the unmatched trailing segments,
100+
// not the already matched route path
101+
val remaining = if (index >= pathArray.size) "" else pathArray.copyOfRange(index, pathArray.size).joinToString("/")
102+
Destination(currentNode, params, remaining)
100103
} else {
101104
null
102105
}

src/test/kotlin/HttpServerTest.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class HttpServerTest {
9090
get("/api/v1/s", ::static)
9191

9292
get("/", ::static)
93-
file("/", folder)
93+
file("/abc", folder)
94+
file("/def/abc", folder)
9495
}
9596

9697
server.start(8080) // Start the server on port 8080
@@ -300,10 +301,15 @@ class HttpServerTest {
300301

301302
@Test
302303
fun testFileEndpoint() {
304+
testFileEndpoint("/abc")
305+
testFileEndpoint("/def/abc")
306+
}
307+
308+
fun testFileEndpoint(prefix: String) {
303309
val files = folder.list() ?: emptyArray()
304310

305311
files.forEach { file ->
306-
val response = makeRequest("/$file")
312+
val response = makeRequest("$prefix/$file")
307313
assertEquals(200, response.code(), "Expected status code 200 for $file")
308314

309315
val responseBody = response.body()?.string()

0 commit comments

Comments
 (0)