Sat, 06 Jan 2024 20:32:56 +0100
Added tag v1.2.2 for changeset 238de141d189
universe@290 | 1 | package de.uapcore.lightpit.filter |
universe@290 | 2 | |
universe@289 | 3 | import jakarta.servlet.FilterChain |
universe@289 | 4 | import jakarta.servlet.annotation.WebFilter |
universe@289 | 5 | import jakarta.servlet.http.HttpFilter |
universe@289 | 6 | import jakarta.servlet.http.HttpServletRequest |
universe@289 | 7 | import jakarta.servlet.http.HttpServletResponse |
universe@289 | 8 | |
universe@289 | 9 | /* |
universe@289 | 10 | * Copyright 2023 Mike Becker. All rights reserved. |
universe@289 | 11 | * |
universe@289 | 12 | * Redistribution and use in source and binary forms, with or without |
universe@289 | 13 | * modification, are permitted provided that the following conditions are met: |
universe@289 | 14 | * |
universe@289 | 15 | * 1. Redistributions of source code must retain the above copyright |
universe@289 | 16 | * notice, this list of conditions and the following disclaimer. |
universe@289 | 17 | * |
universe@289 | 18 | * 2. Redistributions in binary form must reproduce the above copyright |
universe@289 | 19 | * notice, this list of conditions and the following disclaimer in the |
universe@289 | 20 | * documentation and/or other materials provided with the distribution. |
universe@289 | 21 | * |
universe@289 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
universe@289 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
universe@289 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
universe@289 | 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
universe@289 | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
universe@289 | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
universe@289 | 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
universe@289 | 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
universe@289 | 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
universe@289 | 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
universe@289 | 32 | */ |
universe@289 | 33 | |
universe@289 | 34 | @WebFilter(urlPatterns = ["*.ttf", "*.css", "*.js"]) |
universe@289 | 35 | class StaticFilesFilter : HttpFilter() { |
universe@289 | 36 | override fun doFilter(req: HttpServletRequest, res: HttpServletResponse, chain: FilterChain) { |
universe@289 | 37 | // Apply a Cache-Control Header for static files to allow storing them |
universe@289 | 38 | // in shared cache for almost indefinitely. We will cache-bust them when we need an update. |
universe@289 | 39 | // RFC-2616 mandates that servers SHOULD NOT specify more than one year, though |
universe@289 | 40 | res.addHeader("Cache-Control", "public, max-age=31536000, immutable") |
universe@289 | 41 | super.doFilter(req, res, chain) |
universe@289 | 42 | } |
universe@289 | 43 | } |