Skip to content

Commit ef46ef3

Browse files
authored
Merge pull request #459 from splitio/fix-headers
Fix Split’s handler response headers.
2 parents 09cd178 + 17de44d commit ef46ef3

File tree

15 files changed

+19
-143
lines changed

15 files changed

+19
-143
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
4.10.1 (Nov 9, 2023)
2+
- Fixed handler for response http headers.
3+
14
4.10.0 (Nov 2, 2023)
25
- Added support for Flag Sets on the SDK, which enables grouping feature flags and interacting with the group rather than individually (more details in our documentation):
36
- Added new variations of the get treatment methods to support evaluating flags in given flag set/s.

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>4.10.0</version>
8+
<version>4.10.1</version>
99
</parent>
1010
<artifactId>java-client</artifactId>
1111
<packaging>jar</packaging>

client/src/main/java/io/split/client/HttpSegmentChangeFetcher.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
1515
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
1616
import org.apache.hc.core5.http.HttpStatus;
17-
import org.apache.hc.core5.http.Header;
1817
import org.apache.hc.core5.http.io.entity.EntityUtils;
1918
import org.apache.hc.core5.net.URIBuilder;
2019
import org.slf4j.Logger;
@@ -23,8 +22,6 @@
2322
import java.net.URI;
2423
import java.net.URISyntaxException;
2524
import java.nio.charset.StandardCharsets;
26-
import java.util.Arrays;
27-
import java.util.stream.Collectors;
2825

2926
import static com.google.common.base.Preconditions.checkNotNull;
3027

@@ -40,9 +37,6 @@ public final class HttpSegmentChangeFetcher implements SegmentChangeFetcher {
4037
private static final String CACHE_CONTROL_HEADER_NAME = "Cache-Control";
4138
private static final String CACHE_CONTROL_HEADER_VALUE = "no-cache";
4239

43-
private static final String HEADER_FASTLY_DEBUG_NAME = "Fastly-Debug";
44-
private static final String HEADER_FASTLY_DEBUG_VALUE = "1";
45-
4640
private final CloseableHttpClient _client;
4741
private final URI _target;
4842
private final TelemetryRuntimeProducer _telemetryRuntimeProducer;
@@ -81,15 +75,8 @@ public SegmentChange fetch(String segmentName, long since, FetchOptions options)
8175
request.setHeader(CACHE_CONTROL_HEADER_NAME, CACHE_CONTROL_HEADER_VALUE);
8276
}
8377

84-
if (options.fastlyDebugHeaderEnabled()) {
85-
request.addHeader(HEADER_FASTLY_DEBUG_NAME, HEADER_FASTLY_DEBUG_VALUE);
86-
}
87-
8878
response = _client.execute(request);
8979

90-
options.handleResponseHeaders(Arrays.stream(response.getHeaders())
91-
.collect(Collectors.toMap(Header::getName, Header::getValue)));
92-
9380
int statusCode = response.getCode();
9481

9582
if (_log.isDebugEnabled()) {

client/src/main/java/io/split/client/HttpSplitChangeFetcher.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
1515
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
1616
import org.apache.hc.core5.http.HttpStatus;
17-
import org.apache.hc.core5.http.Header;
1817
import org.apache.hc.core5.http.io.entity.EntityUtils;
1918
import org.apache.hc.core5.net.URIBuilder;
2019
import org.slf4j.Logger;
@@ -23,8 +22,6 @@
2322
import java.net.URI;
2423
import java.net.URISyntaxException;
2524
import java.nio.charset.StandardCharsets;
26-
import java.util.Arrays;
27-
import java.util.stream.Collectors;
2825

2926
import static com.google.common.base.Preconditions.checkNotNull;
3027

@@ -41,9 +38,6 @@ public final class HttpSplitChangeFetcher implements SplitChangeFetcher {
4138
private static final String HEADER_CACHE_CONTROL_NAME = "Cache-Control";
4239
private static final String HEADER_CACHE_CONTROL_VALUE = "no-cache";
4340

44-
private static final String HEADER_FASTLY_DEBUG_NAME = "Fastly-Debug";
45-
private static final String HEADER_FASTLY_DEBUG_VALUE = "1";
46-
4741
private final CloseableHttpClient _client;
4842
private final URI _target;
4943
private final TelemetryRuntimeProducer _telemetryRuntimeProducer;
@@ -87,13 +81,7 @@ public SplitChange fetch(long since, FetchOptions options) {
8781
request.setHeader(HEADER_CACHE_CONTROL_NAME, HEADER_CACHE_CONTROL_VALUE);
8882
}
8983

90-
if (options.fastlyDebugHeaderEnabled()) {
91-
request.addHeader(HEADER_FASTLY_DEBUG_NAME, HEADER_FASTLY_DEBUG_VALUE);
92-
}
93-
9484
response = _client.execute(request);
95-
options.handleResponseHeaders(Arrays.stream(response.getHeaders())
96-
.collect(Collectors.toMap(Header::getName, Header::getValue)));
9785

9886
int statusCode = response.getCode();
9987

client/src/main/java/io/split/client/SplitClientConfig.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public class SplitClientConfig {
7373
private final int _uniqueKeysRefreshRateInMemory;
7474
private final int _uniqueKeysRefreshRateRedis;
7575
private static int _filterUniqueKeysRefreshRate;
76-
private final boolean _cdnDebugLogging;
7776
private final OperationMode _operationMode;
7877
private long _validateAfterInactivityInMillis;
7978
private final long _startingSyncCallBackoffBaseMs;
@@ -135,7 +134,6 @@ private SplitClientConfig(String endpoint,
135134
int onDemandFetchRetryDelayMs,
136135
int onDemandFetchMaxRetries,
137136
int failedAttemptsBeforeLogging,
138-
boolean cdnDebugLogging,
139137
OperationMode operationMode,
140138
long validateAfterInactivityInMillis,
141139
long startingSyncCallBackoffBaseMs,
@@ -190,7 +188,6 @@ private SplitClientConfig(String endpoint,
190188
_onDemandFetchRetryDelayMs = onDemandFetchRetryDelayMs;
191189
_onDemandFetchMaxRetries = onDemandFetchMaxRetries;
192190
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
193-
_cdnDebugLogging = cdnDebugLogging;
194191
_operationMode = operationMode;
195192
_storageMode = storageMode;
196193
_validateAfterInactivityInMillis = validateAfterInactivityInMillis;
@@ -367,8 +364,6 @@ public int get_telemetryRefreshRate() {
367364

368365
public int failedAttemptsBeforeLogging() {return _failedAttemptsBeforeLogging;}
369366

370-
public boolean cdnDebugLogging() { return _cdnDebugLogging; }
371-
372367
public OperationMode operationMode() { return _operationMode;}
373368

374369
public long validateAfterInactivityInMillis() {
@@ -445,7 +440,6 @@ public static final class Builder {
445440
private int _onDemandFetchRetryDelayMs = 50;
446441
private final int _onDemandFetchMaxRetries = 10;
447442
private final int _failedAttemptsBeforeLogging = 10;
448-
private final boolean _cdnDebugLogging = true;
449443
private OperationMode _operationMode = OperationMode.STANDALONE;
450444
private long _validateAfterInactivityInMillis = 1000;
451445
private static final long STARTING_SYNC_CALL_BACKOFF_BASE_MS = 1000; //backoff base starting at 1 seconds
@@ -1086,7 +1080,6 @@ public SplitClientConfig build() {
10861080
_onDemandFetchRetryDelayMs,
10871081
_onDemandFetchMaxRetries,
10881082
_failedAttemptsBeforeLogging,
1089-
_cdnDebugLogging,
10901083
_operationMode,
10911084
_validateAfterInactivityInMillis,
10921085
STARTING_SYNC_CALL_BACKOFF_BASE_MS,
Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.split.engine.common;
22

3-
import java.util.Map;
43
import java.util.Objects;
5-
import java.util.function.Function;
64

75
public class FetchOptions {
86

@@ -15,8 +13,6 @@ public Builder() {}
1513
public Builder(FetchOptions opts) {
1614
_targetCN = opts._targetCN;
1715
_cacheControlHeaders = opts._cacheControlHeaders;
18-
_fastlyDebugHeader = opts._fastlyDebugHeader;
19-
_responseHeadersCallback = opts._responseHeadersCallback;
2016
_flagSetsFilter = opts._flagSetsFilter;
2117
}
2218

@@ -25,16 +21,6 @@ public Builder cacheControlHeaders(boolean on) {
2521
return this;
2622
}
2723

28-
public Builder fastlyDebugHeader(boolean on) {
29-
_fastlyDebugHeader = on;
30-
return this;
31-
}
32-
33-
public Builder responseHeadersCallback(Function<Map<String, String>, Void> callback) {
34-
_responseHeadersCallback = callback;
35-
return this;
36-
}
37-
3824
public Builder targetChangeNumber(long targetCN) {
3925
_targetCN = targetCN;
4026
return this;
@@ -46,24 +32,18 @@ public Builder flagSetsFilter(String flagSetsFilter) {
4632
}
4733

4834
public FetchOptions build() {
49-
return new FetchOptions(_cacheControlHeaders, _targetCN, _responseHeadersCallback, _fastlyDebugHeader, _flagSetsFilter);
35+
return new FetchOptions(_cacheControlHeaders, _targetCN, _flagSetsFilter);
5036
}
5137

5238
private long _targetCN = DEFAULT_TARGET_CHANGENUMBER;
5339
private boolean _cacheControlHeaders = false;
54-
private boolean _fastlyDebugHeader = false;
55-
private Function<Map<String, String>, Void> _responseHeadersCallback = null;
5640
private String _flagSetsFilter = "";
5741
}
5842

5943
public boolean cacheControlHeadersEnabled() {
6044
return _cacheControlHeaders;
6145
}
6246

63-
public boolean fastlyDebugHeaderEnabled() {
64-
return _fastlyDebugHeader;
65-
}
66-
6747
public long targetCN() { return _targetCN; }
6848

6949
public boolean hasCustomCN() { return _targetCN != DEFAULT_TARGET_CHANGENUMBER; }
@@ -72,22 +52,11 @@ public String flagSetsFilter() {
7252
return _flagSetsFilter;
7353
}
7454

75-
public void handleResponseHeaders(Map<String, String> headers) {
76-
if (Objects.isNull(_responseHeadersCallback) || Objects.isNull(headers)) {
77-
return;
78-
}
79-
_responseHeadersCallback.apply(headers);
80-
}
81-
8255
private FetchOptions(boolean cacheControlHeaders,
8356
long targetCN,
84-
Function<Map<String, String>, Void> responseHeadersCallback,
85-
boolean fastlyDebugHeader,
8657
String flagSetsFilter) {
8758
_cacheControlHeaders = cacheControlHeaders;
8859
_targetCN = targetCN;
89-
_responseHeadersCallback = responseHeadersCallback;
90-
_fastlyDebugHeader = fastlyDebugHeader;
9160
_flagSetsFilter = flagSetsFilter;
9261
}
9362

@@ -100,21 +69,17 @@ public boolean equals(Object obj) {
10069
FetchOptions other = (FetchOptions) obj;
10170

10271
return Objects.equals(_cacheControlHeaders, other._cacheControlHeaders)
103-
&& Objects.equals(_fastlyDebugHeader, other._fastlyDebugHeader)
104-
&& Objects.equals(_responseHeadersCallback, other._responseHeadersCallback)
10572
&& Objects.equals(_targetCN, other._targetCN)
10673
&& Objects.equals(_flagSetsFilter, other._flagSetsFilter);
10774
}
10875

10976
@Override
11077
public int hashCode() {
111-
return com.google.common.base.Objects.hashCode(_cacheControlHeaders, _fastlyDebugHeader, _responseHeadersCallback,
78+
return com.google.common.base.Objects.hashCode(_cacheControlHeaders,
11279
_targetCN, _flagSetsFilter);
11380
}
11481

11582
private final boolean _cacheControlHeaders;
116-
private final boolean _fastlyDebugHeader;
11783
private final long _targetCN;
118-
private final Function<Map<String, String>, Void> _responseHeadersCallback;
11984
private final String _flagSetsFilter;
12085
}

client/src/main/java/io/split/engine/common/SyncManagerImp.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public static SyncManagerImp build(SplitTasks splitTasks,
9898
config.streamingRetryDelay(),
9999
config.streamingFetchMaxRetries(),
100100
config.failedAttemptsBeforeLogging(),
101-
config.cdnDebugLogging(),
102101
config.getSetsFilter());
103102

104103
PushManager pushManager = PushManagerImp.build(synchronizer,

client/src/main/java/io/split/engine/common/SynchronizerImp.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.split.client.events.EventsTask;
44
import io.split.client.impressions.ImpressionsManager;
55
import io.split.client.impressions.UniqueKeysTracker;
6-
import io.split.client.utils.Json;
76
import io.split.engine.experiments.FetchResult;
87
import io.split.engine.experiments.SplitFetcher;
98
import io.split.engine.experiments.SplitSynchronizationTask;
@@ -17,8 +16,6 @@
1716
import org.slf4j.LoggerFactory;
1817

1918
import java.util.HashSet;
20-
import java.util.List;
21-
import java.util.Map;
2219
import java.util.function.Function;
2320
import java.util.stream.Collectors;
2421

@@ -45,7 +42,6 @@ public class SynchronizerImp implements Synchronizer {
4542
private final int _onDemandFetchRetryDelayMs;
4643
private final int _onDemandFetchMaxRetries;
4744
private final int _failedAttemptsBeforeLogging;
48-
private final boolean _cdnResponseHeadersLogging;
4945
private final String _sets;
5046

5147
public SynchronizerImp(SplitTasks splitTasks,
@@ -55,15 +51,13 @@ public SynchronizerImp(SplitTasks splitTasks,
5551
int onDemandFetchRetryDelayMs,
5652
int onDemandFetchMaxRetries,
5753
int failedAttemptsBeforeLogging,
58-
boolean cdnResponseHeadersLogging,
5954
HashSet<String> sets) {
6055
_splitSynchronizationTask = checkNotNull(splitTasks.getSplitSynchronizationTask());
6156
_splitFetcher = checkNotNull(splitFetcher);
6257
_segmentSynchronizationTaskImp = checkNotNull(splitTasks.getSegmentSynchronizationTask());
6358
_splitCacheProducer = checkNotNull(splitCacheProducer);
6459
this.segmentCacheProducer = checkNotNull(segmentCacheProducer);
6560
_onDemandFetchRetryDelayMs = checkNotNull(onDemandFetchRetryDelayMs);
66-
_cdnResponseHeadersLogging = cdnResponseHeadersLogging;
6761
_onDemandFetchMaxRetries = onDemandFetchMaxRetries;
6862
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
6963
_impressionManager = splitTasks.getImpressionManager();
@@ -135,12 +129,6 @@ private SyncResult attemptSplitsSync(long targetChangeNumber,
135129
}
136130
}
137131

138-
private void logCdnHeaders(String prefix, int maxRetries, int remainingAttempts, List<Map<String, String>> headers) {
139-
if (maxRetries - remainingAttempts > _failedAttemptsBeforeLogging) {
140-
_log.info(String.format("%s: CDN Debug headers: %s", prefix, Json.toJson(headers)));
141-
}
142-
}
143-
144132
@Override
145133
public void refreshSplits(Long targetChangeNumber) {
146134

@@ -151,8 +139,6 @@ public void refreshSplits(Long targetChangeNumber) {
151139
FastlyHeadersCaptor captor = new FastlyHeadersCaptor();
152140
FetchOptions opts = new FetchOptions.Builder()
153141
.cacheControlHeaders(true)
154-
.fastlyDebugHeader(_cdnResponseHeadersLogging)
155-
.responseHeadersCallback(_cdnResponseHeadersLogging ? captor::handle : null)
156142
.flagSetsFilter(_sets)
157143
.build();
158144

@@ -162,9 +148,7 @@ public void refreshSplits(Long targetChangeNumber) {
162148
int attempts = _onDemandFetchMaxRetries - regularResult.remainingAttempts();
163149
if (regularResult.success()) {
164150
_log.debug(String.format("Refresh completed in %s attempts.", attempts));
165-
if (_cdnResponseHeadersLogging) {
166-
logCdnHeaders("[splits]", _onDemandFetchMaxRetries , regularResult.remainingAttempts(), captor.get());
167-
}
151+
168152
regularResult._fetchResult.getSegments().stream()
169153
.forEach(segmentName -> forceRefreshSegment(segmentName));
170154
return;
@@ -184,11 +168,6 @@ public void refreshSplits(Long targetChangeNumber) {
184168
} else {
185169
_log.debug(String.format("No changes fetched after %s attempts with CDN bypassed.", withoutCDNAttempts));
186170
}
187-
188-
if (_cdnResponseHeadersLogging) {
189-
logCdnHeaders("[splits]", _onDemandFetchMaxRetries + ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES,
190-
withCDNBypassed.remainingAttempts(), captor.get());
191-
}
192171
}
193172

194173
@Override
@@ -238,8 +217,6 @@ public void refreshSegment(String segmentName, Long targetChangeNumber) {
238217
FastlyHeadersCaptor captor = new FastlyHeadersCaptor();
239218
FetchOptions opts = new FetchOptions.Builder()
240219
.cacheControlHeaders(true)
241-
.fastlyDebugHeader(_cdnResponseHeadersLogging)
242-
.responseHeadersCallback(_cdnResponseHeadersLogging ? captor::handle : null)
243220
.build();
244221

245222
SyncResult regularResult = attemptSegmentSync(segmentName, targetChangeNumber, opts,
@@ -248,9 +225,7 @@ public void refreshSegment(String segmentName, Long targetChangeNumber) {
248225
int attempts = _onDemandFetchMaxRetries - regularResult.remainingAttempts();
249226
if (regularResult.success()) {
250227
_log.debug(String.format("Segment %s refresh completed in %s attempts.", segmentName, attempts));
251-
if (_cdnResponseHeadersLogging) {
252-
logCdnHeaders(String.format("[segment/%s]", segmentName), _onDemandFetchMaxRetries , regularResult.remainingAttempts(), captor.get());
253-
}
228+
254229
return;
255230
}
256231

@@ -266,11 +241,6 @@ public void refreshSegment(String segmentName, Long targetChangeNumber) {
266241
} else {
267242
_log.debug(String.format("No changes fetched for segment %s after %s attempts with CDN bypassed.", segmentName, withoutCDNAttempts));
268243
}
269-
270-
if (_cdnResponseHeadersLogging) {
271-
logCdnHeaders(String.format("[segment/%s]", segmentName), _onDemandFetchMaxRetries + ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES,
272-
withCDNBypassed.remainingAttempts(), captor.get());
273-
}
274244
}
275245

276246
@Override

0 commit comments

Comments
 (0)