kean / Pulse

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

Added a new experimental method of swizzling URLSession #121

Closed flashspys closed 1 year ago

flashspys commented 1 year ago

Hey,

unfortunately we are also using URLSession as in #113 and #120. To enable the NetworkLogger support nevertheless, I adapted the method swizzling that is used by Bagel, ported it to Swift and connected it to the network logger. As far as I can test, this method works without any modification of existing code for custom URLSessions and URLSession.shared. It would be great to hear your feedback!

kean commented 1 year ago

Hi @flashspys. This looks great and it would be an awesome addition, but I'm not sure I can include it in the main project because it uses private APIs, and to use Pulse, you need to integrate it into the app. Maybe it could be provided as a code sample, hidden under #if DEBUG directive instead? Not sure what are the other options.

kean commented 1 year ago

I added the code to a public gist and documented it. I'm going to close the PR because I don't think this code can be safely bundled in the framework.

Btw, have you tried using Experimental.URLSessionProxy? It is included in the framework. It's a bit more intrusive that what you suggest, but it doesn't use any private APIs. I just tested it and it works with URLSession.shared and the native Async/Await APIs.