From fe8f140f041a50ec7c084ce7cc16995871c374b4 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 20 Mar 2012 15:03:26 -0700 Subject: [PATCH] Recognize /static/.../ and serve long expiration headers. --- core/src/main/java/hudson/Plugin.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/Plugin.java b/core/src/main/java/hudson/Plugin.java index bf5f4a6821..20f671e8dc 100644 --- a/core/src/main/java/hudson/Plugin.java +++ b/core/src/main/java/hudson/Plugin.java @@ -23,12 +23,14 @@ */ package hudson; +import hudson.util.TimeUnit2; import jenkins.model.Jenkins; import hudson.model.Descriptor; import hudson.model.Saveable; import hudson.model.listeners.ItemListener; import hudson.model.listeners.SaveableListener; import hudson.model.Descriptor.FormException; +import org.kohsuke.stapler.MetaClass; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -208,8 +210,16 @@ public abstract class Plugin implements Saveable { return; } + // Stapler routes requests like the "/static/.../foo/bar/zot" to be treated like "/foo/bar/zot" + // and this is used to serve long expiration header, by using Jenkins.VERSION_HASH as "..." + // to create unique URLs. Recognize that and set a long expiration header. + String requestPath = req.getRequestURI().substring(req.getContextPath().length()); + boolean staticLink = requestPath.startsWith("/static/"); + + long expires = staticLink ? TimeUnit2.DAYS.toMillis(365) : -1; + // use serveLocalizedFile to support automatic locale selection - rsp.serveLocalizedFile(req, new URL(wrapper.baseResourceURL,'.'+path)); + rsp.serveLocalizedFile(req, new URL(wrapper.baseResourceURL,'.'+path),expires); } // -- GitLab