Skip to content

Commit 7232cfa

Browse files
committed
Merge requested headers with default headers on write instead of on read
Seems more efficient - getNetworkRequestHeaders/getNetworkResponseHeaders is invoked on every http request but setNetwork... is only invoked on start-up
1 parent 46eb26a commit 7232cfa

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

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

33
import io.sentry.protocol.SdkVersion;
44
import io.sentry.util.SampleRateUtils;
5-
import java.util.ArrayList;
5+
66
import java.util.Arrays;
77
import java.util.LinkedHashSet;
88
import java.util.List;
@@ -197,13 +197,14 @@ public enum SentryReplayQuality {
197197
* Additional request headers to capture for URLs defined in networkDetailAllowUrls. The default
198198
* headers (Content-Type, Content-Length, Accept) are always included in addition to these.
199199
*/
200-
private @NotNull List<String> networkRequestHeaders = new ArrayList<>();
200+
private @NotNull String[] networkRequestHeaders = DEFAULT_HEADERS.clone();
201201

202202
/**
203203
* Additional response headers to capture for URLs defined in networkDetailAllowUrls. The default
204204
* headers (Content-Type, Content-Length, Accept) are always included in addition to these.
205205
*/
206-
private @NotNull List<String> networkResponseHeaders = new ArrayList<>();
206+
private @NotNull String[] networkResponseHeaders = DEFAULT_HEADERS.clone();
207+
207208

208209
public SentryReplayOptions(final boolean empty, final @Nullable SdkVersion sdkVersion) {
209210
if (!empty) {
@@ -488,38 +489,37 @@ public void setNetworkCaptureBodies(final boolean networkCaptureBodies) {
488489
* @return the complete network request headers array
489490
*/
490491
public @NotNull String[] getNetworkRequestHeaders() {
491-
return mergeHeaders(DEFAULT_HEADERS, networkRequestHeaders);
492+
return networkRequestHeaders;
492493
}
493494

494495
/**
495-
* Sets additional request headers to capture for URLs defined in networkDetailAllowUrls. The
496+
* Sets request headers to capture for URLs defined in networkDetailAllowUrls. The
496497
* default headers (Content-Type, Content-Length, Accept) are always included automatically.
497498
*
498499
* @param networkRequestHeaders additional network request headers list
499500
*/
500501
public void setNetworkRequestHeaders(final @NotNull List<String> networkRequestHeaders) {
501-
this.networkRequestHeaders = new ArrayList<>(networkRequestHeaders);
502+
this.networkRequestHeaders = mergeHeaders(DEFAULT_HEADERS, networkRequestHeaders);
502503
}
503504

504505
/**
505506
* Gets all response headers to capture for URLs defined in networkDetailAllowUrls. This includes
506-
* both the default headers (Content-Type, Content-Length, Content-Encoding) and any additional
507-
* headers.
507+
* both the default headers (Content-Type, Content-Length, Accept) and any additional headers.
508508
*
509509
* @return the complete network response headers array
510510
*/
511511
public @NotNull String[] getNetworkResponseHeaders() {
512-
return mergeHeaders(DEFAULT_HEADERS, networkResponseHeaders);
512+
return networkResponseHeaders;
513513
}
514514

515515
/**
516-
* Sets additional response headers to capture for URLs defined in networkDetailAllowUrls. The
516+
* Sets response headers to capture for URLs defined in networkDetailAllowUrls. The
517517
* default headers (Content-Type, Content-Length, Accept) are always included automatically.
518518
*
519519
* @param networkResponseHeaders the additional network response headers list
520520
*/
521521
public void setNetworkResponseHeaders(final @NotNull List<String> networkResponseHeaders) {
522-
this.networkResponseHeaders = new ArrayList<>(networkResponseHeaders);
522+
this.networkResponseHeaders = mergeHeaders(DEFAULT_HEADERS, networkResponseHeaders);
523523
}
524524

525525
/**

0 commit comments

Comments
 (0)