Handle HEAD requests

This commit is contained in:
kageru 2019-09-29 16:20:50 +02:00
parent facb408e89
commit 0f1bd98f49

@ -11,11 +11,13 @@ import io.ktor.http.content.streamProvider
import io.ktor.locations.KtorExperimentalLocationsAPI
import io.ktor.locations.Location
import io.ktor.locations.get
import io.ktor.locations.head
import io.ktor.request.receiveMultipart
import io.ktor.response.respond
import io.ktor.response.respondText
import io.ktor.routing.Routing
import io.ktor.routing.get
import io.ktor.routing.head
import io.ktor.routing.post
import moe.kageru.kodeshare.config.ServerSpec
import moe.kageru.kodeshare.config.config
@ -54,6 +56,26 @@ object Routes {
get<TypedPasteRequest> { req ->
call.handleGet(req)
}
head("/") {
call.respond(HttpStatusCode.OK)
}
head<RawPasteRequest> { req ->
call.handleHead(req)
}
head<TypedPasteRequest> { req ->
call.handleHead(req)
}
head<PasteRequest> { req ->
call.handleHead(req)
}
}
private suspend fun ApplicationCall.handleHead(paste: AbstractPasteRequest) {
if (PasteDao.selectByUri(paste.uri) != null) {
respond(HttpStatusCode.OK)
} else {
respond(HttpStatusCode.NotFound)
}
}
@ExperimentalStdlibApi