10
10
*/
11
11
package io .vertx .httpproxy .impl ;
12
12
13
+ import java .math .BigInteger ;
14
+
13
15
/**
14
16
* @author <a href="mailto:[email protected] ">Julien Viet</a>
15
17
*/
16
18
public class CacheControl {
17
19
18
20
private int maxAge ;
21
+ private int maxStale ;
22
+ private int minFresh ;
23
+ private boolean noCache ;
24
+ private boolean noStore ;
25
+ private boolean noTransform ;
26
+ private boolean onlyIfCached ;
27
+ private boolean mustRevalidate ;
28
+ private boolean mustUnderstand ;
29
+ private boolean _private ;
30
+ private boolean proxyRevalidate ;
19
31
private boolean _public ;
32
+ private int sMaxage ;
20
33
21
34
public CacheControl parse (String header ) {
22
- maxAge = -1 ;
35
+ noCache = false ;
36
+ noStore = false ;
37
+ noTransform = false ;
38
+ onlyIfCached = false ;
39
+ mustRevalidate = false ;
40
+ mustUnderstand = false ;
41
+ _private = false ;
42
+ proxyRevalidate = false ;
23
43
_public = false ;
44
+
24
45
String [] parts = header .split ("," ); // No regex
25
46
for (String part : parts ) {
26
47
part = part .trim ().toLowerCase ();
27
48
switch (part ) {
28
49
case "public" :
29
50
_public = true ;
30
51
break ;
52
+ case "no-cache" :
53
+ noCache = true ;
54
+ break ;
55
+ case "no-store" :
56
+ noStore = true ;
57
+ break ;
58
+ case "no-transform" :
59
+ noTransform = true ;
60
+ break ;
61
+ case "only-if-cached" :
62
+ onlyIfCached = true ;
63
+ break ;
64
+ case "must-revalidate" :
65
+ mustRevalidate = true ;
66
+ break ;
67
+ case "must-understand" :
68
+ mustUnderstand = true ;
69
+ break ;
70
+ case "private" :
71
+ _private = true ;
72
+ break ;
73
+ case "proxy-revalidate" :
74
+ proxyRevalidate = true ;
75
+ break ;
31
76
default :
32
- if (part . startsWith ( "max-age=" )) {
33
- maxAge = Integer . parseInt (part . substring ( 8 ) );
34
-
35
- }
77
+ maxAge = loadInt (part , "max-age=" );
78
+ maxStale = loadInt (part , "max-stale=" );
79
+ minFresh = loadInt ( part , "min-fresh=" );
80
+ sMaxage = loadInt ( part , "s-maxage=" );
36
81
break ;
37
82
}
38
83
}
39
84
return this ;
40
85
}
41
86
87
+ private static int loadInt (String part , String prefix ) {
88
+ if (part .startsWith (prefix )) {
89
+ BigInteger valueRaw = new BigInteger (part .substring (prefix .length ()));
90
+ return valueRaw
91
+ .min (BigInteger .valueOf (Integer .MAX_VALUE ))
92
+ .max (BigInteger .ZERO ).intValueExact ();
93
+ }
94
+ return -1 ;
95
+ }
96
+
42
97
public int maxAge () {
43
98
return maxAge ;
44
99
}
@@ -47,4 +102,47 @@ public boolean isPublic() {
47
102
return _public ;
48
103
}
49
104
105
+ public int maxStale () {
106
+ return maxStale ;
107
+ }
108
+
109
+ public int minFresh () {
110
+ return minFresh ;
111
+ }
112
+
113
+ public boolean isNoCache () {
114
+ return noCache ;
115
+ }
116
+
117
+ public boolean isNoStore () {
118
+ return noStore ;
119
+ }
120
+
121
+ public boolean isNoTransform () {
122
+ return noTransform ;
123
+ }
124
+
125
+ public boolean isOnlyIfCached () {
126
+ return onlyIfCached ;
127
+ }
128
+
129
+ public boolean isMustRevalidate () {
130
+ return mustRevalidate ;
131
+ }
132
+
133
+ public boolean isMustUnderstand () {
134
+ return mustUnderstand ;
135
+ }
136
+
137
+ public boolean isPrivate () {
138
+ return _private ;
139
+ }
140
+
141
+ public boolean isProxyRevalidate () {
142
+ return proxyRevalidate ;
143
+ }
144
+
145
+ public int sMaxage () {
146
+ return sMaxage ;
147
+ }
50
148
}
0 commit comments