ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
13.07k stars 1.07k forks source link

Add support for ports in withTestApplication #720

Open dave08 opened 6 years ago

dave08 commented 6 years ago

Currently there is no parameter for which port to use in sending a test request, I propose to add this function:

fun TestApplicationEngine.handleRequest(
    method: HttpMethod,
    port: Int = 80,
    uri: String,
    setup: TestApplicationRequest.() -> Unit = {}
): TestApplicationCall = handleRequest {
    this.uri = uri
    this.method = method
    this.addHeader(HttpHeaders.Host, "localhost:$port")
    setup()
}
brushmate commented 5 years ago

This functionality can be simulated by setting the Host header:

handleRequest(Get, "/") {
    addHeader(HttpHeaders.Host, "localhost:1234")
}.apply {
    assertEquals(1234, request.port())
}
oleg-larshin commented 4 years ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.