I fixed this issue the above way. Now I had a fuct...
# ktor
a
I fixed this issue the above way. Now I had a fuction:
Copy code
fun PipelineContext<ApplicationCall>.withValidCredentials(body: PipelineContext<ApplicationCall>.(ApplicationCall) -> Unit) {
	val credentials = call.request.basicAuthenticationCredentials()
	val principal = authenticate(credentials)
	if (principal != null) {
		body.invoke(this, call)
	} else throw InvalidCredentialsException()
}
and I use it like this:
Copy code
fun Routing.backup() {
	post("/backup") {
		withValidCredentials {
			val multipart = call.request.content.get<MultiPartData>()
			val credentials = call.request.basicAuthenticationCredentials()!!
			call.response.contentType(ContentType.Text.Plain)
			call.respondWrite {
				if (!call.request.isMultipart()) {
					appendln("Not a multipart request")
				} else {
					multipart.parts.forEach { handlePart(it, credentials.name) }
				}
			}
		}
	}
}
because withValidCredentionals is not defined on a Route the
call.respondWrite
is invalid