5
5
import java .util .function .Function ;
6
6
7
7
public class FetchOptions {
8
-
8
+
9
+ public static final Long DEFAULT_TARGET_CHANGENUMBER = -1L ;
10
+
9
11
public static class Builder {
10
12
11
13
public Builder () {}
12
14
13
15
public Builder (FetchOptions opts ) {
14
- _cdnBypass = opts ._cdnBypass ;
16
+ _targetCN = opts ._targetCN ;
15
17
_cacheControlHeaders = opts ._cacheControlHeaders ;
16
18
_fastlyDebugHeader = opts ._fastlyDebugHeader ;
17
19
_responseHeadersCallback = opts ._responseHeadersCallback ;
@@ -32,16 +34,16 @@ public Builder responseHeadersCallback(Function<Map<String, String>, Void> callb
32
34
return this ;
33
35
}
34
36
35
- public Builder cdnBypass ( boolean bypass ) {
36
- _cdnBypass = bypass ;
37
+ public Builder targetChangeNumber ( long targetCN ) {
38
+ _targetCN = targetCN ;
37
39
return this ;
38
40
}
39
41
40
42
public FetchOptions build () {
41
- return new FetchOptions (_cacheControlHeaders , _cdnBypass , _responseHeadersCallback , _fastlyDebugHeader );
43
+ return new FetchOptions (_cacheControlHeaders , _targetCN , _responseHeadersCallback , _fastlyDebugHeader );
42
44
}
43
45
44
- private boolean _cdnBypass = false ;
46
+ private long _targetCN = DEFAULT_TARGET_CHANGENUMBER ;
45
47
private boolean _cacheControlHeaders = false ;
46
48
private boolean _fastlyDebugHeader = false ;
47
49
private Function <Map <String , String >, Void > _responseHeadersCallback = null ;
@@ -55,7 +57,9 @@ public boolean fastlyDebugHeaderEnabled() {
55
57
return _fastlyDebugHeader ;
56
58
}
57
59
58
- public boolean cdnBypass () { return _cdnBypass ; }
60
+ public long targetCN () { return _targetCN ; }
61
+
62
+ public boolean hasCustomCN () { return _targetCN != DEFAULT_TARGET_CHANGENUMBER ; }
59
63
60
64
public void handleResponseHeaders (Map <String , String > headers ) {
61
65
if (Objects .isNull (_responseHeadersCallback ) || Objects .isNull (headers )) {
@@ -65,11 +69,11 @@ public void handleResponseHeaders(Map<String, String> headers) {
65
69
}
66
70
67
71
private FetchOptions (boolean cacheControlHeaders ,
68
- boolean cdnBypass ,
72
+ long targetCN ,
69
73
Function <Map <String , String >, Void > responseHeadersCallback ,
70
74
boolean fastlyDebugHeader ) {
71
75
_cacheControlHeaders = cacheControlHeaders ;
72
- _cdnBypass = cdnBypass ;
76
+ _targetCN = targetCN ;
73
77
_responseHeadersCallback = responseHeadersCallback ;
74
78
_fastlyDebugHeader = fastlyDebugHeader ;
75
79
}
@@ -84,16 +88,17 @@ public boolean equals(Object obj) {
84
88
85
89
return Objects .equals (_cacheControlHeaders , other ._cacheControlHeaders )
86
90
&& Objects .equals (_fastlyDebugHeader , other ._fastlyDebugHeader )
87
- && Objects .equals (_responseHeadersCallback , other ._responseHeadersCallback );
91
+ && Objects .equals (_responseHeadersCallback , other ._responseHeadersCallback )
92
+ && Objects .equals (_targetCN , other ._targetCN );
88
93
}
89
94
90
95
@ Override
91
96
public int hashCode () {
92
- return com .google .common .base .Objects .hashCode (_cacheControlHeaders , _fastlyDebugHeader , _responseHeadersCallback );
97
+ return com .google .common .base .Objects .hashCode (_cacheControlHeaders , _fastlyDebugHeader , _responseHeadersCallback , _targetCN );
93
98
}
94
99
95
100
private final boolean _cacheControlHeaders ;
96
101
private final boolean _fastlyDebugHeader ;
97
- private final boolean _cdnBypass ;
102
+ private final long _targetCN ;
98
103
private final Function <Map <String , String >, Void > _responseHeadersCallback ;
99
104
}
0 commit comments