From 4d6c0cd3af17bc7ac4b07183d69e10596ab1c701 Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Mon, 4 Sep 2023 21:05:40 +1000 Subject: [PATCH] Upgrade vaadin and importmap and add caching Signed-off-by: Phillip Kruger --- bom/application/pom.xml | 4 +- .../quarkus/devui/runtime/MvnpmHandler.java | 41 +++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 45bc122623fee..4cfc187c32ae1 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -225,8 +225,8 @@ 3.0.0 2.12.3 - 1.0.9 - 24.1.4 + 1.0.10 + 24.1.6 2.8.0 3.3.3 2.8.0 diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/devui/runtime/MvnpmHandler.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/devui/runtime/MvnpmHandler.java index 5d68e31d9c382..6b5a7d961fe56 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/devui/runtime/MvnpmHandler.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/devui/runtime/MvnpmHandler.java @@ -5,6 +5,13 @@ import java.io.UncheckedIOException; import java.net.URL; import java.net.URLClassLoader; +import java.net.URLConnection; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; +import java.util.Locale; import java.util.Set; import io.vertx.core.Handler; @@ -22,7 +29,7 @@ public class MvnpmHandler implements Handler { public MvnpmHandler(String root, Set mvnpmJars) { this.root = root; - this.mvnpmLoader = new URLClassLoader(mvnpmJars.toArray(new URL[] {})); + this.mvnpmLoader = new URLClassLoader(mvnpmJars.toArray(URL[]::new)); } @Override @@ -37,13 +44,20 @@ public void handle(RoutingContext event) { } try { - InputStream is = mvnpmLoader.getResourceAsStream(BASE_DIR + fullPath); - if (is != null) { - byte[] contents = is.readAllBytes(); - event.response() - .putHeader(HttpHeaders.CONTENT_TYPE, getContentType(fileName)) - .end(Buffer.buffer(contents)); - return; + URL url = mvnpmLoader.getResource(BASE_DIR + fullPath); + URLConnection openConnection = url.openConnection(); + long lastModified = openConnection.getLastModified(); + try (InputStream is = openConnection.getInputStream()) { + if (is != null) { + byte[] contents = is.readAllBytes(); + event.response() + .putHeader(HttpHeaders.CONTENT_TYPE, getContentType(fileName)) + .putHeader(HttpHeaders.CACHE_CONTROL, "public, immutable, max-age=31536000") + .putHeader(HttpHeaders.LAST_MODIFIED, formatDate(lastModified)) + .putHeader("date", formatDate(LocalDateTime.now())) + .end(Buffer.buffer(contents)); + return; + } } } catch (IOException ex) { throw new UncheckedIOException(ex); @@ -51,6 +65,17 @@ public void handle(RoutingContext event) { event.next(); } + private String formatDate(long m) { + Instant i = Instant.ofEpochMilli(m); + return formatDate(i); + } + + private String formatDate(TemporalAccessor t) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH) + .withZone(ZoneId.of("GMT")); + return formatter.format(t); + } + private String getContentType(String filename) { String f = filename.toLowerCase(); if (f.endsWith(DOT_JS)) {