1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.util.web.Page
4 import net.pterodactylus.util.web.Request
5 import net.pterodactylus.util.web.Response
9 * [Page] implementation that delivers static files from the filesystem.
11 class ReloadingPage<R: Request>(private val prefix: String, private val path: String, private val mimeType: String): Page<R> {
13 override fun isPrefixPage() = true
15 override fun getPath() = prefix
17 override fun handleRequest(request: R, response: Response): Response {
18 val filename = request.uri.path.split("/").last()
19 File(path, filename).also { file ->
21 response.content.use { output ->
22 file.forEachBlock { buffer, bytesRead ->
23 output.write(buffer, 0, bytesRead)
26 response.statusCode = 200
27 response.contentType = mimeType
29 response.statusCode = 404
30 response.statusText = "Not found"