-
-
Notifications
You must be signed in to change notification settings - Fork 462
feat(replay): Capture network request/response details when using SentryOkHttpListener #4919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
43jay
wants to merge
8
commits into
main
Choose a base branch
from
43jay/MOBILE-935
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b5ea38f
Use case-insensitive comparision when extracting headers
43jay 5841544
Extract network details when using SentryOkHttpEventListener
43jay 5dc9fab
CHANGELOG for Network Details extraction
43jay 9016498
unit tests
43jay e6d7289
Format code
getsentry-bot 4b30647
bug: fix NullPointerException if allowedHeaders contains null
43jay af6765d
bug: fix Duplicate HTTP headers lost in conversion
43jay 050c3a6
bug: fix Set-Cookie headers incorrectly concatenated with comma separ…
43jay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
sentry/src/test/java/io/sentry/util/network/NetworkDetailCaptureUtilsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package io.sentry.util.network | ||
|
|
||
| import java.util.LinkedHashMap | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertTrue | ||
| import org.junit.Test | ||
|
|
||
| class NetworkDetailCaptureUtilsTest { | ||
|
|
||
| @Test | ||
| fun `getCaptureHeaders should match headers case-insensitively`() { | ||
| // Setup: allHeaders with mixed case keys | ||
| val allHeaders = | ||
| LinkedHashMap<String, String>().apply { | ||
| put("Content-Type", "application/json") | ||
| put("Authorization", "Bearer token123") | ||
| put("X-Custom-Header", "custom-value") | ||
| put("accept", "application/json") | ||
| } | ||
|
|
||
| // Test: allowedHeaders with different casing | ||
| val allowedHeaders = arrayOf("content-type", "AUTHORIZATION", "x-custom-header", "ACCEPT") | ||
|
|
||
| val result = NetworkDetailCaptureUtils.getCaptureHeaders(allHeaders, allowedHeaders) | ||
|
|
||
| // All headers should be matched despite case differences | ||
| assertEquals(4, result.size) | ||
|
|
||
| // Original casing should be preserved in output | ||
| assertEquals("application/json", result["Content-Type"]) | ||
| assertEquals("Bearer token123", result["Authorization"]) | ||
| assertEquals("custom-value", result["X-Custom-Header"]) | ||
| assertEquals("application/json", result["accept"]) | ||
|
|
||
| // Verify keys maintain original casing from allHeaders | ||
| assertTrue(result.containsKey("Content-Type")) | ||
| assertTrue(result.containsKey("Authorization")) | ||
| assertTrue(result.containsKey("X-Custom-Header")) | ||
| assertTrue(result.containsKey("accept")) | ||
| } | ||
|
|
||
| @Test | ||
| fun `getCaptureHeaders should handle null allHeaders`() { | ||
| val allowedHeaders = arrayOf("content-type") | ||
|
|
||
| val result = NetworkDetailCaptureUtils.getCaptureHeaders(null, allowedHeaders) | ||
|
|
||
| assertTrue(result.isEmpty()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `getCaptureHeaders should handle empty allowedHeaders`() { | ||
| val allHeaders = mapOf("Content-Type" to "application/json") | ||
| val allowedHeaders = arrayOf<String>() | ||
|
|
||
| val result = NetworkDetailCaptureUtils.getCaptureHeaders(allHeaders, allowedHeaders) | ||
|
|
||
| assertTrue(result.isEmpty()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `getCaptureHeaders should only capture allowed headers`() { | ||
| val allHeaders = | ||
| mapOf( | ||
| "Content-Type" to "application/json", | ||
| "Authorization" to "Bearer token123", | ||
| "X-Unwanted-Header" to "should-not-appear", | ||
| ) | ||
|
|
||
| val allowedHeaders = arrayOf("content-type", "authorization") | ||
|
|
||
| val result = NetworkDetailCaptureUtils.getCaptureHeaders(allHeaders, allowedHeaders) | ||
|
|
||
| assertEquals(2, result.size) | ||
| assertEquals("application/json", result["Content-Type"]) | ||
| assertEquals("Bearer token123", result["Authorization"]) | ||
|
|
||
| // Unwanted header should not be present | ||
| assertTrue(!result.containsKey("X-Unwanted-Header")) | ||
| } | ||
|
|
||
| @Test | ||
| fun `getCaptureHeaders should handle null elements in allowedHeaders`() { | ||
| val allHeaders = | ||
| mapOf( | ||
| "Content-Type" to "application/json", | ||
| "Authorization" to "Bearer token123", | ||
| "X-Custom-Header" to "custom-value", | ||
| ) | ||
|
|
||
| // allowedHeaders contains null elements which should be ignored | ||
| val allowedHeaders = arrayOf(null, "content-type", null, "authorization", null) | ||
|
|
||
| val result = NetworkDetailCaptureUtils.getCaptureHeaders(allHeaders, allowedHeaders) | ||
|
|
||
| // Only non-null allowed headers should be matched | ||
| assertEquals(2, result.size) | ||
| assertEquals("application/json", result["Content-Type"]) | ||
| assertEquals("Bearer token123", result["Authorization"]) | ||
|
|
||
| // X-Custom-Header should not be present as it's not in the allowed list | ||
| assertTrue(!result.containsKey("X-Custom-Header")) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Set-Cookie headers incorrectly concatenated with comma separator
The
toMap()function concatenates duplicate HTTP headers with comma separators, butSet-Cookieis an exception that cannot be concatenated this way per RFC 6265. Cookie values can contain commas in attributes like expiration dates, causing the concatenated value to become unparseable. This corruptsSet-Cookieheaders when multiple cookies are set, breaking network detail capture for session replay.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed