55import io .split .Spec ;
66import io .split .client .dtos .SplitChange ;
77import io .split .client .dtos .SplitHttpResponse ;
8- import io .split .client .dtos .RuleBasedSegment ;
98import io .split .client .dtos .SplitChangesOldPayloadDto ;
109import io .split .client .dtos .ChangeDto ;
1110import io .split .client .dtos .Split ;
2524
2625import java .net .URI ;
2726import java .net .URISyntaxException ;
28- import java .util .ArrayList ;
2927
3028import static com .google .common .base .Preconditions .checkNotNull ;
31- import static io .split .Spec .SPEC_VERSION ;
3229import static io .split .Spec .SPEC_1_3 ;
3330import static io .split .Spec .SPEC_1_1 ;
3431
@@ -44,6 +41,7 @@ public final class HttpSplitChangeFetcher implements SplitChangeFetcher {
4441 private static final String TILL = "till" ;
4542 private static final String SETS = "sets" ;
4643 private static final String SPEC = "s" ;
44+ private String specVersion = SPEC_1_3 ;
4745 private int PROXY_CHECK_INTERVAL_MILLISECONDS_SS = 24 * 60 * 60 * 1000 ;
4846 private Long _lastProxyCheckTimestamp = 0L ;
4947 private final SplitHttpClient _client ;
@@ -75,22 +73,23 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
7573 long start = System .currentTimeMillis ();
7674 SplitHttpResponse response ;
7775 try {
78- if (SPEC_VERSION .equals (SPEC_1_1 ) && (System .currentTimeMillis () - _lastProxyCheckTimestamp >= PROXY_CHECK_INTERVAL_MILLISECONDS_SS )) {
76+ if (specVersion .equals (SPEC_1_1 ) && (System .currentTimeMillis () - _lastProxyCheckTimestamp >= PROXY_CHECK_INTERVAL_MILLISECONDS_SS )) {
7977 _log .info ("Switching to new Feature flag spec ({}) and fetching." , SPEC_1_3 );
80- SPEC_VERSION = SPEC_1_3 ;
78+ specVersion = SPEC_1_3 ;
8179 since = -1 ;
8280 sinceRBS = -1 ;
8381 }
8482 URI uri = buildURL (options , since , sinceRBS );
83+ _log .error (uri .toString ());
8584 response = _client .get (uri , options , null );
8685 if (response .statusCode () < HttpStatus .SC_OK || response .statusCode () >= HttpStatus .SC_MULTIPLE_CHOICES ) {
8786 if (response .statusCode () == HttpStatus .SC_REQUEST_URI_TOO_LONG ) {
8887 _log .error ("The amount of flag sets provided are big causing uri length error." );
8988 throw new UriTooLongException (String .format ("Status code: %s. Message: %s" , response .statusCode (), response .statusMessage ()));
9089 }
9190
92- if (response .statusCode () == HttpStatus .SC_BAD_REQUEST && SPEC_VERSION .equals (Spec .SPEC_1_3 ) && _rootURIOverriden ) {
93- SPEC_VERSION = Spec .SPEC_1_1 ;
91+ if (response .statusCode () == HttpStatus .SC_BAD_REQUEST && specVersion .equals (Spec .SPEC_1_3 ) && _rootURIOverriden ) {
92+ specVersion = Spec .SPEC_1_1 ;
9493 _log .warn ("Detected proxy without support for Feature flags spec {} version, will switch to spec version {}" ,
9594 SPEC_1_3 , SPEC_1_1 );
9695 _lastProxyCheckTimestamp = System .currentTimeMillis ();
@@ -109,12 +108,12 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
109108 }
110109
111110 SplitChange splitChange = new SplitChange ();
112- if (SPEC_VERSION .equals (Spec .SPEC_1_1 )) {
111+ if (specVersion .equals (Spec .SPEC_1_1 )) {
113112 splitChange .featureFlags = convertBodyToOldSpec (response .body ());
114113 splitChange .ruleBasedSegments = ChangeDto .createEmptyDto ();
115114 } else {
116115 splitChange = Json .fromJson (response .body (), SplitChange .class );
117- if (SPEC_VERSION .equals (Spec .SPEC_1_3 ) && _lastProxyCheckTimestamp != 0 ) {
116+ if (specVersion .equals (Spec .SPEC_1_3 ) && _lastProxyCheckTimestamp != 0 ) {
118117 splitChange .clearCache = true ;
119118 _lastProxyCheckTimestamp = 0L ;
120119 }
@@ -127,9 +126,9 @@ private ChangeDto<Split> convertBodyToOldSpec(String body) {
127126 }
128127
129128 private URI buildURL (FetchOptions options , long since , long sinceRBS ) throws URISyntaxException {
130- URIBuilder uriBuilder = new URIBuilder (_target ).addParameter (SPEC , "" + SPEC_VERSION );
129+ URIBuilder uriBuilder = new URIBuilder (_target ).addParameter (SPEC , "" + specVersion );
131130 uriBuilder .addParameter (SINCE , "" + since );
132- if (SPEC_VERSION .equals (SPEC_1_3 )) {
131+ if (specVersion .equals (SPEC_1_3 )) {
133132 uriBuilder .addParameter (RB_SINCE , "" + sinceRBS );
134133 }
135134 if (!options .flagSetsFilter ().isEmpty ()) {
0 commit comments