SWHttpTrafficRecorder
SWHttpTrafficRecorder copied to clipboard
Added method swizzling for default session configuration, is now compatible with AFNetworking
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 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:
-
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; -
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 I'll have to take a look at it later I've been busy with other projects at the moment.
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 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.