feat(network-details): Implement header and body extraction#7585
feat(network-details): Implement header and body extraction#758543jay wants to merge 3 commits intomobile-935/new-swizzlingfrom
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## mobile-935/new-swizzling #7585 +/- ##
============================================================
Coverage ? 85.009%
============================================================
Files ? 486
Lines ? 28965
Branches ? 12610
============================================================
Hits ? 24623
Misses ? 4293
Partials ? 49
Continue to review full report in Codecov by Sentry.
|
9473efb to
5bc5830
Compare
3547546 to
e7c5abb
Compare
7faf4ef to
6e19c0a
Compare
e7c5abb to
2e9607e
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
|
|
||
| var warnings = [NetworkBodyWarning]() | ||
| let lower = contentType?.lowercased() ?? "" | ||
| let utType = contentType.flatMap { UTType(mimeType: $0.lowercased()) } |
There was a problem hiding this comment.
Content-type parameters cause UTType MIME lookup failure
High Severity
UTType(mimeType:) expects a bare MIME type (e.g. "application/json") but real-world Content-Type headers typically include parameters like "application/json; charset=utf-8". Passing the full value with parameters causes UTType initialization to return nil, so the JSON and text branches are skipped entirely. The body then falls through to the else branch and produces a "[Body not captured: …]" placeholder instead of parsing the content. The form-urlencoded branch is unaffected because it uses contains. Stripping parameters (splitting on ";" and taking the first component) before calling UTType(mimeType:) would fix this.
1) Extracts bodies that are JSON, formurlencoded, or text. Uses UTType to accurately classify content types as JSON or text without maintaining a manual list. Falls back to a string match for application/x-www-form-urlencoded which has no UTType representation. !Relies on having a valid `contentType` 2) Populates NetworkBodyWarning's for "MAYBE_JSON_TRUNCATED" "TEXT_TRUNCATED" "BODY_PARSE_ERROR" ^when encountered, these show custom dashboard UI.
Uses UTType to classify content types: only content positively identified as text is decoded. Everything else gets a descriptive placeholder: Example - "[Body not captured: contentType=image/png (8 bytes)]" Known text types (where UTType conforms to .text) are reliably classified by UTType's type hierarchy. If a content type header is incorrect (e.g. claims text but contains binary), the resulting decode failure is caught by the existing bodyParseError warning.
Casts to lower-case before comparing headers. ObjC setters now accept raw allHeaders and configuredHeaders instead of pre-filtered headers, keeping the filtering logic in Swift.
6e19c0a to
9a8d48d
Compare
2e9607e to
6e5c5bb
Compare


📜 Description
SentryNetworkBodyExtract request/response bodies that are either JSON, formurlencoded, binary or text.
NSData).NSUTF8StringEncoding, thenNSISOLatin1StringEncodingthen gives up with aBODY_PARSE_ERRORwarning.SentryReplayNetworkRequestOrResponse💡 Motivation and Context
See first PR in stack.
💚 How did you test it?
Unit tests
📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled. N/ACloses #7587