Skip to content

Commit 174245e

Browse files
committed
Update API to accept List<String> everywhere
Previously some api was expecting String[], others were using List<String>. Change everything to List<String> for consistency
1 parent aa31589 commit 174245e

File tree

7 files changed

+92
-89
lines changed

7 files changed

+92
-89
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ static void applyMetadata(
507507
}
508508

509509
// Network Details Configuration
510-
if (options.getSessionReplay().getNetworkDetailAllowUrls().length == 0) {
510+
if (options.getSessionReplay().getNetworkDetailAllowUrls().isEmpty()) {
511511
final @Nullable List<String> allowUrls =
512512
readList(metadata, logger, REPLAYS_NETWORK_DETAIL_ALLOW_URLS);
513513
if (allowUrls != null && !allowUrls.isEmpty()) {
@@ -521,12 +521,12 @@ static void applyMetadata(
521521
if (!filteredUrls.isEmpty()) {
522522
options
523523
.getSessionReplay()
524-
.setNetworkDetailAllowUrls(filteredUrls.toArray(new String[0]));
524+
.setNetworkDetailAllowUrls(filteredUrls);
525525
}
526526
}
527527
}
528528

529-
if (options.getSessionReplay().getNetworkDetailDenyUrls().length == 0) {
529+
if (options.getSessionReplay().getNetworkDetailDenyUrls().isEmpty()) {
530530
final @Nullable List<String> denyUrls =
531531
readList(metadata, logger, REPLAYS_NETWORK_DETAIL_DENY_URLS);
532532
if (denyUrls != null && !denyUrls.isEmpty()) {
@@ -540,7 +540,7 @@ static void applyMetadata(
540540
if (!filteredUrls.isEmpty()) {
541541
options
542542
.getSessionReplay()
543-
.setNetworkDetailDenyUrls(filteredUrls.toArray(new String[0]));
543+
.setNetworkDetailDenyUrls(filteredUrls);
544544
}
545545
}
546546
}
@@ -554,7 +554,7 @@ static void applyMetadata(
554554
REPLAYS_NETWORK_CAPTURE_BODIES,
555555
options.getSessionReplay().isNetworkCaptureBodies() /* defaultValue */));
556556

557-
if (options.getSessionReplay().getNetworkRequestHeaders().length
557+
if (options.getSessionReplay().getNetworkRequestHeaders().size()
558558
== SentryReplayOptions.getNetworkDetailsDefaultHeaders().size()) { // Only has defaults
559559
final @Nullable List<String> requestHeaders =
560560
readList(metadata, logger, REPLAYS_NETWORK_REQUEST_HEADERS);
@@ -572,7 +572,7 @@ static void applyMetadata(
572572
}
573573
}
574574

575-
if (options.getSessionReplay().getNetworkResponseHeaders().length
575+
if (options.getSessionReplay().getNetworkResponseHeaders().size()
576576
== SentryReplayOptions.getNetworkDetailsDefaultHeaders().size()) { // Only has defaults
577577
final @Nullable List<String> responseHeaders =
578578
readList(metadata, logger, REPLAYS_NETWORK_RESPONSE_HEADERS);

sentry/api/sentry.api

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,11 +3801,11 @@ public final class io/sentry/SentryReplayOptions {
38013801
public fun getFrameRate ()I
38023802
public fun getMaskViewClasses ()Ljava/util/Set;
38033803
public fun getMaskViewContainerClass ()Ljava/lang/String;
3804-
public fun getNetworkDetailAllowUrls ()[Ljava/lang/String;
3805-
public fun getNetworkDetailDenyUrls ()[Ljava/lang/String;
3804+
public fun getNetworkDetailAllowUrls ()Ljava/util/List;
3805+
public fun getNetworkDetailDenyUrls ()Ljava/util/List;
38063806
public static fun getNetworkDetailsDefaultHeaders ()Ljava/util/List;
3807-
public fun getNetworkRequestHeaders ()[Ljava/lang/String;
3808-
public fun getNetworkResponseHeaders ()[Ljava/lang/String;
3807+
public fun getNetworkRequestHeaders ()Ljava/util/List;
3808+
public fun getNetworkResponseHeaders ()Ljava/util/List;
38093809
public fun getOnErrorSampleRate ()Ljava/lang/Double;
38103810
public fun getQuality ()Lio/sentry/SentryReplayOptions$SentryReplayQuality;
38113811
public fun getScreenshotStrategy ()Lio/sentry/ScreenshotStrategyType;
@@ -3825,8 +3825,8 @@ public final class io/sentry/SentryReplayOptions {
38253825
public fun setMaskAllText (Z)V
38263826
public fun setMaskViewContainerClass (Ljava/lang/String;)V
38273827
public fun setNetworkCaptureBodies (Z)V
3828-
public fun setNetworkDetailAllowUrls ([Ljava/lang/String;)V
3829-
public fun setNetworkDetailDenyUrls ([Ljava/lang/String;)V
3828+
public fun setNetworkDetailAllowUrls (Ljava/util/List;)V
3829+
public fun setNetworkDetailDenyUrls (Ljava/util/List;)V
38303830
public fun setNetworkRequestHeaders (Ljava/util/List;)V
38313831
public fun setNetworkResponseHeaders (Ljava/util/List;)V
38323832
public fun setOnErrorSampleRate (Ljava/lang/Double;)V
@@ -7496,9 +7496,9 @@ public final class io/sentry/util/network/NetworkBodyParser {
74967496
}
74977497

74987498
public final class io/sentry/util/network/NetworkDetailCaptureUtils {
7499-
public static fun createRequest (Ljava/lang/Object;Ljava/lang/Long;ZLio/sentry/util/network/NetworkDetailCaptureUtils$NetworkBodyExtractor;[Ljava/lang/String;Lio/sentry/util/network/NetworkDetailCaptureUtils$NetworkHeaderExtractor;)Lio/sentry/util/network/ReplayNetworkRequestOrResponse;
7500-
public static fun createResponse (Ljava/lang/Object;Ljava/lang/Long;ZLio/sentry/util/network/NetworkDetailCaptureUtils$NetworkBodyExtractor;[Ljava/lang/String;Lio/sentry/util/network/NetworkDetailCaptureUtils$NetworkHeaderExtractor;)Lio/sentry/util/network/ReplayNetworkRequestOrResponse;
7501-
public static fun initializeForUrl (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)Lio/sentry/util/network/NetworkRequestData;
7499+
public static fun createRequest (Ljava/lang/Object;Ljava/lang/Long;ZLio/sentry/util/network/NetworkDetailCaptureUtils$NetworkBodyExtractor;Ljava/util/List;Lio/sentry/util/network/NetworkDetailCaptureUtils$NetworkHeaderExtractor;)Lio/sentry/util/network/ReplayNetworkRequestOrResponse;
7500+
public static fun createResponse (Ljava/lang/Object;Ljava/lang/Long;ZLio/sentry/util/network/NetworkDetailCaptureUtils$NetworkBodyExtractor;Ljava/util/List;Lio/sentry/util/network/NetworkDetailCaptureUtils$NetworkHeaderExtractor;)Lio/sentry/util/network/ReplayNetworkRequestOrResponse;
7501+
public static fun initializeForUrl (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;)Lio/sentry/util/network/NetworkRequestData;
75027502
}
75037503

75047504
public abstract interface class io/sentry/util/network/NetworkDetailCaptureUtils$NetworkBodyExtractor {

sentry/src/main/java/io/sentry/SentryReplayOptions.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.sentry.protocol.SdkVersion;
44
import io.sentry.util.SampleRateUtils;
5+
import java.util.ArrayList;
56
import java.util.Arrays;
67
import java.util.Collections;
78
import java.util.LinkedHashSet;
@@ -165,18 +166,18 @@ public enum SentryReplayQuality {
165166
* Capture request and response details for XHR and fetch requests that match the given URLs.
166167
* Default is empty (network details not collected).
167168
*/
168-
private @NotNull String[] networkDetailAllowUrls = new String[0];
169+
private @NotNull List<String> networkDetailAllowUrls = Collections.emptyList();
169170

170171
/**
171172
* Do not capture request and response details for these URLs. Takes precedence over
172173
* networkDetailAllowUrls. Default is empty.
173174
*/
174-
private @NotNull String[] networkDetailDenyUrls = new String[0];
175+
private @NotNull List<String> networkDetailDenyUrls = Collections.emptyList();
175176

176177
/**
177178
* Decide whether to capture request and response bodies for URLs defined in
178179
* networkDetailAllowUrls. Default is true, but capturing bodies requires at least one url
179-
* specified via {@link #setNetworkDetailAllowUrls(String[])}.
180+
* specified via {@link #setNetworkDetailAllowUrls(List)}.
180181
*/
181182
private boolean networkCaptureBodies = true;
182183

@@ -198,13 +199,13 @@ public enum SentryReplayQuality {
198199
* Additional request headers to capture for URLs defined in networkDetailAllowUrls. The default
199200
* headers (Content-Type, Content-Length, Accept) are always included in addition to these.
200201
*/
201-
private @NotNull String[] networkRequestHeaders = DEFAULT_HEADERS.toArray(new String[0]);
202+
private @NotNull List<String> networkRequestHeaders = DEFAULT_HEADERS;
202203

203204
/**
204205
* Additional response headers to capture for URLs defined in networkDetailAllowUrls. The default
205206
* headers (Content-Type, Content-Length, Accept) are always included in addition to these.
206207
*/
207-
private @NotNull String[] networkResponseHeaders = DEFAULT_HEADERS.toArray(new String[0]);
208+
private @NotNull List<String> networkResponseHeaders = DEFAULT_HEADERS;
208209

209210
public SentryReplayOptions(final boolean empty, final @Nullable SdkVersion sdkVersion) {
210211
if (!empty) {
@@ -428,40 +429,40 @@ public void setScreenshotStrategy(final @NotNull ScreenshotStrategyType screensh
428429
}
429430

430431
/**
431-
* Gets the array of URLs for which network request and response details should be captured.
432+
* Gets the list of URLs for which network request and response details should be captured.
432433
*
433-
* @return the network detail allow URLs array
434+
* @return the network detail allow URLs list
434435
*/
435-
public @NotNull String[] getNetworkDetailAllowUrls() {
436+
public @NotNull List<String> getNetworkDetailAllowUrls() {
436437
return networkDetailAllowUrls;
437438
}
438439

439440
/**
440-
* Sets the array of URLs for which network request and response details should be captured.
441+
* Sets the list of URLs for which network request and response details should be captured.
441442
*
442-
* @param networkDetailAllowUrls the network detail allow URLs array
443+
* @param networkDetailAllowUrls the network detail allow URLs list
443444
*/
444-
public void setNetworkDetailAllowUrls(final @NotNull String[] networkDetailAllowUrls) {
445-
this.networkDetailAllowUrls = networkDetailAllowUrls;
445+
public void setNetworkDetailAllowUrls(final @NotNull List<String> networkDetailAllowUrls) {
446+
this.networkDetailAllowUrls = Collections.unmodifiableList(new ArrayList<>(networkDetailAllowUrls));
446447
}
447448

448449
/**
449-
* Gets the array of URLs for which network request and response details should NOT be captured.
450+
* Gets the list of URLs for which network request and response details should NOT be captured.
450451
*
451-
* @return the network detail deny URLs array
452+
* @return the network detail deny URLs list
452453
*/
453-
public @NotNull String[] getNetworkDetailDenyUrls() {
454+
public @NotNull List<String> getNetworkDetailDenyUrls() {
454455
return networkDetailDenyUrls;
455456
}
456457

457458
/**
458-
* Sets the array of URLs for which network request and response details should NOT be captured.
459+
* Sets the list of URLs for which network request and response details should NOT be captured.
459460
* Takes precedence over networkDetailAllowUrls.
460461
*
461-
* @param networkDetailDenyUrls the network detail deny URLs array
462+
* @param networkDetailDenyUrls the network detail deny URLs list
462463
*/
463-
public void setNetworkDetailDenyUrls(final @NotNull String[] networkDetailDenyUrls) {
464-
this.networkDetailDenyUrls = networkDetailDenyUrls;
464+
public void setNetworkDetailDenyUrls(final @NotNull List<String> networkDetailDenyUrls) {
465+
this.networkDetailDenyUrls = Collections.unmodifiableList(new ArrayList<>(networkDetailDenyUrls));
465466
}
466467

467468
/**
@@ -486,9 +487,9 @@ public void setNetworkCaptureBodies(final boolean networkCaptureBodies) {
486487
* Gets all request headers to capture for URLs defined in networkDetailAllowUrls. This includes
487488
* both the default headers (Content-Type, Content-Length, Accept) and any additional headers.
488489
*
489-
* @return the complete network request headers array
490+
* @return an unmodifiable list of the request headers to extract
490491
*/
491-
public @NotNull String[] getNetworkRequestHeaders() {
492+
public @NotNull List<String> getNetworkRequestHeaders() {
492493
return networkRequestHeaders;
493494
}
494495

@@ -506,9 +507,9 @@ public void setNetworkRequestHeaders(final @NotNull List<String> networkRequestH
506507
* Gets all response headers to capture for URLs defined in networkDetailAllowUrls. This includes
507508
* both the default headers (Content-Type, Content-Length, Accept) and any additional headers.
508509
*
509-
* @return the complete network response headers array
510+
* @return an unmodifiable list of the response headers to extract
510511
*/
511-
public @NotNull String[] getNetworkResponseHeaders() {
512+
public @NotNull List<String> getNetworkResponseHeaders() {
512513
return networkResponseHeaders;
513514
}
514515

@@ -527,12 +528,13 @@ public void setNetworkResponseHeaders(final @NotNull List<String> networkRespons
527528
*
528529
* @param defaultHeaders the default headers that are always included
529530
* @param additionalHeaders additional headers to merge
531+
* @return an unmodifiable list of merged headers
530532
*/
531-
private static @NotNull String[] mergeHeaders(
533+
private static @NotNull List<String> mergeHeaders(
532534
final @NotNull List<String> defaultHeaders, final @NotNull List<String> additionalHeaders) {
533535
final Set<String> merged = new LinkedHashSet<>();
534536
merged.addAll(defaultHeaders);
535537
merged.addAll(additionalHeaders);
536-
return merged.toArray(new String[0]);
538+
return Collections.unmodifiableList(new ArrayList<>(merged));
537539
}
538540
}

sentry/src/main/java/io/sentry/rrweb/RRWebOptionsEvent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ public RRWebOptionsEvent(final @NotNull SentryOptions options) {
6060
: "canvas";
6161
optionsPayload.put("screenshotStrategy", screenshotStrategy);
6262
optionsPayload.put(
63-
"networkDetailHasUrls", replayOptions.getNetworkDetailAllowUrls().length > 0);
63+
"networkDetailHasUrls", !replayOptions.getNetworkDetailAllowUrls().isEmpty());
6464

6565
// Add network detail configuration options
66-
if (replayOptions.getNetworkDetailAllowUrls().length > 0) {
66+
if (!replayOptions.getNetworkDetailAllowUrls().isEmpty()) {
6767
optionsPayload.put("networkDetailAllowUrls", replayOptions.getNetworkDetailAllowUrls());
6868

6969
optionsPayload.put("networkRequestHeaders", replayOptions.getNetworkRequestHeaders());
7070
optionsPayload.put("networkResponseHeaders", replayOptions.getNetworkResponseHeaders());
7171
optionsPayload.put("networkCaptureBodies", replayOptions.isNetworkCaptureBodies());
7272

73-
if (replayOptions.getNetworkDetailDenyUrls().length > 0) {
73+
if (!replayOptions.getNetworkDetailDenyUrls().isEmpty()) {
7474
optionsPayload.put("networkDetailDenyUrls", replayOptions.getNetworkDetailDenyUrls());
7575
}
7676
}

sentry/src/main/java/io/sentry/util/network/NetworkDetailCaptureUtils.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.HashSet;
44
import java.util.LinkedHashMap;
5+
import java.util.List;
56
import java.util.Locale;
67
import java.util.Map;
78
import java.util.Set;
@@ -32,8 +33,8 @@ public interface NetworkHeaderExtractor<T> {
3233
public static @Nullable NetworkRequestData initializeForUrl(
3334
@NotNull final String url,
3435
@Nullable final String method,
35-
@Nullable final String[] networkDetailAllowUrls,
36-
@Nullable final String[] networkDetailDenyUrls) {
36+
@Nullable final List<String> networkDetailAllowUrls,
37+
@Nullable final List<String> networkDetailDenyUrls) {
3738

3839
if (!shouldCaptureUrl(url, networkDetailAllowUrls, networkDetailDenyUrls)) {
3940
return null;
@@ -51,7 +52,7 @@ public interface NetworkHeaderExtractor<T> {
5152
@Nullable final Long bodySize,
5253
final boolean networkCaptureBodies,
5354
@NotNull final NetworkBodyExtractor<T> bodyExtractor,
54-
@NotNull final String[] networkRequestHeaders,
55+
@NotNull final List<String> networkRequestHeaders,
5556
@NotNull final NetworkHeaderExtractor<T> headerExtractor) {
5657

5758
return createRequestOrResponseInternal(
@@ -68,7 +69,7 @@ public interface NetworkHeaderExtractor<T> {
6869
@Nullable final Long bodySize,
6970
final boolean networkCaptureBodies,
7071
@NotNull final NetworkBodyExtractor<T> bodyExtractor,
71-
@NotNull final String[] networkResponseHeaders,
72+
@NotNull final List<String> networkResponseHeaders,
7273
@NotNull final NetworkHeaderExtractor<T> headerExtractor) {
7374

7475
return createRequestOrResponseInternal(
@@ -85,15 +86,15 @@ public interface NetworkHeaderExtractor<T> {
8586
* href="https://docs.sentry.io/platforms/javascript/session-replay/configuration/">docs.sentry.io</a>
8687
*
8788
* @param url The URL to check
88-
* @param networkDetailAllowUrls Array of regex patterns that allow capture
89-
* @param networkDetailDenyUrls Array of regex patterns to explicitly deny capture. Takes
89+
* @param networkDetailAllowUrls List of regex patterns that allow capture
90+
* @param networkDetailDenyUrls List of regex patterns to explicitly deny capture. Takes
9091
* precedence over networkDetailAllowUrls.
9192
* @return true if the URL should be captured, false otherwise
9293
*/
9394
private static boolean shouldCaptureUrl(
9495
@NotNull final String url,
95-
@Nullable final String[] networkDetailAllowUrls,
96-
@Nullable final String[] networkDetailDenyUrls) {
96+
@Nullable final List<String> networkDetailAllowUrls,
97+
@Nullable final List<String> networkDetailDenyUrls) {
9798

9899
// If there are deny patterns and URL matches any, don't capture.
99100
if (networkDetailDenyUrls != null) {
@@ -121,10 +122,10 @@ private static boolean shouldCaptureUrl(
121122

122123
@VisibleForTesting
123124
static @NotNull Map<String, String> getCaptureHeaders(
124-
@Nullable final Map<String, String> allHeaders, @NotNull final String[] allowedHeaders) {
125+
@Nullable final Map<String, String> allHeaders, @NotNull final List<String> allowedHeaders) {
125126

126127
final Map<String, String> capturedHeaders = new LinkedHashMap<>();
127-
if (allHeaders == null || allowedHeaders.length == 0) {
128+
if (allHeaders == null) {
128129
return capturedHeaders;
129130
}
130131

@@ -150,7 +151,7 @@ private static boolean shouldCaptureUrl(
150151
@Nullable final Long bodySize,
151152
final boolean networkCaptureBodies,
152153
@NotNull final NetworkBodyExtractor<T> bodyExtractor,
153-
@NotNull final String[] allowedHeaders,
154+
@NotNull final List<String> allowedHeaders,
154155
@NotNull final NetworkHeaderExtractor<T> headerExtractor) {
155156

156157
NetworkBody body = null;

0 commit comments

Comments
 (0)