feat(network): add logRequest API for traffic that bypasses URLSession (gRPC, custom transports) - #442
Merged
maatheusgois-dd merged 2 commits intoAug 28, 2026
Conversation
…, custom transports) DebugSwift's network inspector captures URLSession traffic via swizzling, but transports that bypass URLSession entirely (gRPC over SwiftNIO, custom sockets) are invisible to it, and HttpModel/HttpDatasource are internal, so apps have no way to surface those calls in the Network tab. Adds DebugSwift.Network.shared.logRequest(...) that builds an HttpModel, routes it through the existing pipeline (ignoredURLs/onlyURLs filtering, ErrorHelper status mapping, reloadHttp_DebugSwift UI refresh) and returns whether the entry was stored. Includes unit tests and a README section with a gRPC interceptor example.
HttpDatasource is main-thread-confined (the capture pipeline reports via @mainactor), but logRequest ran the store on the caller's thread — a data race when called from gRPC event loops. Off-main calls now evaluate URL filters synchronously and hop the store+notification to main. Extracts passesURLFilters from addHttpRequest for reuse.
Contributor
Author
|
Pushed a follow-up commit: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds
DebugSwift.Network.shared.logRequest(...)— a public API to log requests that bypassURLSessionand are therefore invisible to the swizzler: gRPC over SwiftNIO (grpc-swift), custom sockets, or any hand-rolled transport. Logged entries appear in the Network tab alongside automatically captured traffic.Today
HttpModelandHttpDatasourceare internal, so apps using gRPC have no way to surface those calls in DebugSwift. This is a universal entry point rather than a gRPC-specific integration: any transport can feed the Network tab through it.Approach
The method builds an
HttpModeland routes it through the existing pipeline, so behavior matches automatically captured traffic:ignoredURLs/onlyURLsfiltering viaHttpDatasource.addHttpRequestErrorHelperreloadHttp_DebugSwiftnotification (same asWKWebViewNetworkMonitor)Boolso callers know whether the entry was storedNo changes to existing behavior — purely additive.
Public API
Type of change
Test plan
Manual test steps
DebugSwift.Network.shared.logRequest(...)from a gRPC client interceptor (or any code path outsideURLSession).ignoredURLsand repeat — the entry is filtered out andlogRequestreturnsfalse.Tests
NetworkCustomRequestLoggingTests(6 tests): field mapping, error →isSuccess == false,ignoredURLs/onlyURLsfiltering, reload notification, zero-duration default.The package also builds in Swift 6 language mode.
Files Changed
DebugSwift.Network.swift— newlogRequest(...)public methodNetworkCustomRequestLoggingTests.swift(new) — 6 testsREADME.md— "Custom Request Logging (gRPC and other non-URLSession transports)" section with a gRPC interceptor exampleChecklist