Also, when using `withTestApplication` and multipl...
# ktor
d
Also, when using
withTestApplication
and multiple connectors (and testing on port), how will the test know how to request from a particular port?
This did it:
Copy code
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()
}
Shouldn't it be added to Ktor?
c
Perhaps.. could you please open a ticket?
d
Sure, I'm also using
Copy code
data class HttpPortRouteSelector(val port: Int) : RouteSelector(RouteSelectorEvaluation.qualityParameter) {
	override fun evaluate(context: RoutingResolveContext, segmentIndex: Int): RouteSelectorEvaluation {
		if (context.call.request.local.port == port)
			return RouteSelectorEvaluation.Constant
		return RouteSelectorEvaluation.Failed
	}

	override fun toString(): String = "(port:$port)"
}

@ContextDsl
fun Route.port(port: Int, build: Route.() -> Unit): Route {
	val selector = HttpPortRouteSelector(port)
	return createChild(selector).apply(build)
}
Should I include it in the same ticket or open a new one for this? Also it might be nice to include support for declaring multiple ports in Hocon and embeddedServer configs...
It happens often enough to have one port for internal api, one for external api, and possibly one for metrics... it keeps the api neat in each case...
And it's easier to configure HAProxy or Nginx to redirect a domain name to a port than starting to map url pieces...
Should I just open the ticket on the first issue @cy?
In the meantime I just opened the first issue: https://github.com/ktorio/ktor/issues/720