Norbi
04/24/2023, 10:38 PMtestApplication {}
and its client
but in some cases (?) the request URL is prepended by <http://localhost>
. So for example /service/etc
becomes <http://localhost/service/etc>
when I POST the request, resulting in error 404.
Have you seen something similar?
Thanks.Aleksei Tirman [JB]
04/25/2023, 7:15 AMNorbi
04/25/2023, 7:50 AM@Test
fun testUrlIssue() = testApplication {
routing {
post("/{a}/{b}") {
}
}
val httpClient = // or: client
createClient {
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.ALL
}
}
val response = <http://httpClient.post|httpClient.post>("/a/1")
assertEquals(HttpStatusCode.OK, response.status) // expected: <200 OK> but was: <404 Not Found>
}
Log:
09:49:47.583 [Test worker @coroutine#2] INFO io.ktor.client.HttpClient - REQUEST: <http://localhost/a/1>
METHOD: HttpMethod(value=POST)
COMMON HEADERS
-> Accept: */*
-> Accept-Charset: UTF-8
CONTENT HEADERS
-> Content-Length: 0
BODY Content-Type: null
BODY START
BODY END
09:49:47.680 [DefaultDispatcher-worker-1 @call-context#3] INFO ktor.test - No ktor.deployment.watch patterns specified, automatic reload is not active.
09:49:47.732 [DefaultDispatcher-worker-1 @call-context#3] INFO ktor.test - Application started in 0.08 seconds.
09:49:48.255 [DefaultDispatcher-worker-1 @coroutine#8] INFO io.ktor.client.HttpClient - RESPONSE: 404 Not Found
METHOD: HttpMethod(value=POST)
FROM: <http://localhost/a/1>
COMMON HEADERS
-> Content-Length: 0
BODY Content-Type: null
BODY START
BODY END
expected: <200 OK> but was: <404 Not Found>
Expected :200 OK
Actual :404 Not Found
Thanks.Aleksei Tirman [JB]
04/25/2023, 9:57 AMrouting {
post("/{a}/{b}") {
call.respond(HttpStatusCode.OK)
}
}
Norbi
04/25/2023, 11:28 AM