kean / Pulse

Network logger for Apple platforms
https://pulselogger.com
MIT License
6.37k stars 311 forks source link

Add URLSessionProxy #285

Closed kean closed 2 months ago

kean commented 2 months ago

This PR adds two new standard ways for capturing network requests.

Option 1 (Quick). If you are evaluating the framework, the quickest way to get started is with NetworkLogger/enableProxy(logger:).

#if DEBUG
NetworkLogger.enableProxy()
#endif

Option 2 (Recommended). Use URLSessionProxy, a thin wrapper on top of URLSession.

let session: URLSessionProtocol

#if DEBUG
let session: URLSessionProtocol = URLSessionProxy(configuration: .default)
#else
let session: URLSessionProtocol = URLSession(configuration: .default)
#endif

Alternative way to exclude Pulse entirely from the build:

#if DEBUG
typealias URLSessionType = URLSessionProxy
#else
typealias URLSessionType = URLSession
#endif