7
7
8
8
@ FunctionalInterface
9
9
public interface FileResponseHandler {
10
- record Cache (Duration duration , boolean gzip , boolean cacheStyleAndScripts ) implements FileResponseHandler {
10
+ record Cache (Duration duration , Duration styleAndScriptDuration , boolean gzip ) implements FileResponseHandler {
11
11
@ Override
12
12
public HTTPResponse apply (HTTPResponse response , boolean directory , Path path ) {
13
13
if (!directory ) {
14
- if (!duration .isZero ()) {
15
- if (cacheStyleAndScripts ) {
16
- response = response .publicCache (duration );
17
- } else {
18
- var n = path .toString ();
19
-
20
- if (n .endsWith (".css" ) || n .endsWith (".js" )) {
21
- response = response .noCache ();
22
- } else {
23
- response = response .publicCache (duration );
24
- }
25
- }
26
- }
14
+ var n = path .getFileName ().toString ();
15
+ response = response .publicCache (n .endsWith (".css" ) || n .endsWith (".js" ) ? styleAndScriptDuration : duration );
27
16
28
17
if (gzip ) {
29
18
response = response .gzip ();
@@ -37,12 +26,12 @@ public HTTPResponse apply(HTTPResponse response, boolean directory, Path path) {
37
26
FileResponseHandler CACHE_5_MIN = cache (Duration .ofMinutes (5L ));
38
27
FileResponseHandler CACHE_1_HOUR = cache (Duration .ofHours (1L ));
39
28
40
- static FileResponseHandler cache (Duration duration , boolean gzip , boolean cacheStyleAndScripts ) {
41
- return new Cache (duration , gzip , cacheStyleAndScripts );
29
+ static FileResponseHandler cache (Duration duration , Duration styleAndScriptDuration , boolean gzip ) {
30
+ return new Cache (duration , styleAndScriptDuration , gzip );
42
31
}
43
32
44
33
static FileResponseHandler cache (Duration duration ) {
45
- return new Cache (duration , true , false );
34
+ return new Cache (duration , duration , true );
46
35
}
47
36
48
37
HTTPResponse apply (HTTPResponse response , boolean directory , Path path );
0 commit comments