SWHttpTrafficRecorder icon indicating copy to clipboard operation
SWHttpTrafficRecorder copied to clipboard

Added method swizzling for default session configuration, is now compatible with AFNetworking

Open Amindv1 opened this issue 8 years ago • 4 comments

I added method swizzling so we add the SWprotocol to the NSURLProtocols default session every time it gets initialized. Tried to keep same coding style. Also added a isEnabled function to the SWHttpTrafficRecorder class that enables/disables the recorder for a provided session configuration.

Amindv1 avatar Dec 20 '16 20:12 Amindv1

@Amindv1 Thanks for the pulling request to enhance the tool and sorry that I was not looking into this earlier due to vacations.

I looked at the pull request and have the following preliminary feedbacks:

  1. If this pull request is merged, after we enable recording for default session config, we do not have a way to remove/stop it; maybe what we can do is to enable recording for default sessions through swizzling introduced in this pull request while users call existing methods like - (BOOL)startRecording(when a session config is not provided, put it around Line 104 of SWHttpTrafficRecorder.m), and then stop recording when - (void)stopRecording is called;

  2. The implementation of (void)setEnabled:(BOOL)enabled forConfig:(NSURLSessionConfiguration*)sessionConfig can be merged with existing implementation of - (BOOL)startRecordingAtPath:(NSString *)recordingPath forSessionConfiguration:(NSURLSessionConfiguration *)sessionConfig error:(NSError **) error to avoid duplicate code.

JinlianWang avatar Jan 01 '17 17:01 JinlianWang

@JinlianWang I'll have to take a look at it later I've been busy with other projects at the moment.

Amindv1 avatar Jan 12 '17 02:01 Amindv1

Hey @Amindv1 curious if you were thinking of revisiting this PR, as I definitely think it's very valuable when working with libraries that don't expose the NSURLSessionConfiguration.

loudmouth avatar Apr 20 '17 09:04 loudmouth

@loudmouth It's not likely anytime soon you can just fork off my repo and use it, everything works the only reason the PR isnt merged is because of the above mentioned things.

Amindv1 avatar May 03 '17 16:05 Amindv1