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