Skip to content

Commit 588c1c8

Browse files
add etag for resource files
timestamp values aren't reliable, as they are set to 0 in built jar
1 parent 4379d65 commit 588c1c8

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/main/kotlin/com/viaversion/aas/web/ViaWebApp.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.viaversion.aas.web
22

3+
import com.viaversion.aas.AspirinServer
34
import io.ktor.http.*
45
import io.ktor.http.content.*
56
import io.ktor.serialization.gson.*
@@ -109,19 +110,26 @@ class ViaWebApp(val viaWebServer: WebServer) {
109110
val relativePath = Path.of(call.parameters.getAll("path")?.joinToString("/") ?: "")
110111
val index = Path.of("index.html")
111112

112-
val resource = call.resolveResource(relativePath.toString(), "web")
113-
?: call.resolveResource(relativePath.resolve(index).toString(), "web")
114-
115113
var file = File("config/web/").combineSafe(relativePath)
116114
if (file.isDirectory) {
117115
file = file.resolve(index.toFile())
118116
}
119117

120-
when {
121-
file.isFile -> call.respondFile(file)
122-
resource != null -> call.respond(resource)
123-
else -> call.respond(HttpStatusCode.NotFound, "404 Not Found")
118+
if (file.isFile) {
119+
call.respondFile(file)
120+
return
124121
}
122+
123+
val resource = call.resolveResource(relativePath.toString(), "web")
124+
?: call.resolveResource(relativePath.resolve(index).toString(), "web")
125+
126+
if (resource != null) {
127+
resource.versions += EntityTagVersion("resource." + AspirinServer.version, weak = true)
128+
call.respond(resource)
129+
return
130+
}
131+
132+
call.respond(HttpStatusCode.NotFound, "404 Not Found")
125133
}
126134

127135
private fun Route.routeWs() {

0 commit comments

Comments
 (0)