universe@289: import jakarta.servlet.FilterChain universe@289: import jakarta.servlet.annotation.WebFilter universe@289: import jakarta.servlet.http.HttpFilter universe@289: import jakarta.servlet.http.HttpServletRequest universe@289: import jakarta.servlet.http.HttpServletResponse universe@289: universe@289: /* universe@289: * Copyright 2023 Mike Becker. All rights reserved. universe@289: * universe@289: * Redistribution and use in source and binary forms, with or without universe@289: * modification, are permitted provided that the following conditions are met: universe@289: * universe@289: * 1. Redistributions of source code must retain the above copyright universe@289: * notice, this list of conditions and the following disclaimer. universe@289: * universe@289: * 2. Redistributions in binary form must reproduce the above copyright universe@289: * notice, this list of conditions and the following disclaimer in the universe@289: * documentation and/or other materials provided with the distribution. universe@289: * universe@289: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@289: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@289: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE universe@289: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE universe@289: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL universe@289: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR universe@289: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER universe@289: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, universe@289: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE universe@289: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. universe@289: */ universe@289: universe@289: @WebFilter(urlPatterns = ["*.ttf", "*.css", "*.js"]) universe@289: class StaticFilesFilter : HttpFilter() { universe@289: override fun doFilter(req: HttpServletRequest, res: HttpServletResponse, chain: FilterChain) { universe@289: // Apply a Cache-Control Header for static files to allow storing them universe@289: // in shared cache for almost indefinitely. We will cache-bust them when we need an update. universe@289: // RFC-2616 mandates that servers SHOULD NOT specify more than one year, though universe@289: res.addHeader("Cache-Control", "public, max-age=31536000, immutable") universe@289: super.doFilter(req, res, chain) universe@289: } universe@289: }