SWHttpTrafficRecorder provides an easy way to record all the HTTP(s) traffic in the device’s file system while the user is using your app at the same time. It can be used for different purposes, like testing, replaying the workflow or logging an app's network activity for debugging purposes. See OHHTTPStubs, Nocilla or Mocktail for examples of how the recorded files can be used (this library is inspired while using the above frameworks). This library has been developed solely for testing purposes. We highly recommend against using it in production environment. However, if you choose to include it anyway, there are security considerations that must be taken into account.
Note: if you like this library, please feel free to fork or star it using the buttons on the top of this page.
The recommended way to add SWHttpTrafficRecorder to your project. Add
SWHttpTrafficRecorder to your
Add this repo to your
Or since the library contains only two files (
SWHttpTrafficRecorder.m), you can just drop them anywhere in your project and it is done.
Even though the library is highly customizable, you can get started just by inserting one line of code.
[[SWHttpTrafficRecorder sharedRecorder] startRecording];
NSURLSession is supported, including AFNetworking, or any networking framework that use Cocoa's URL Loading System.
To use with
NSURLSession based requests, you need to provide the
NSURLSessionConfiguration to record, see the method
- (BOOL)startRecordingAtPath:(NSString *)recordingPath forSessionConfiguration:(NSURLSessionConfiguration *)sessionConfig error:(NSError **) error.
The library can be used to record the HTTP(s) traffic in 3 commonly used formats: Mocktail, response body only and HTTP(s) Raw Message (the format output by
curl -is). In addition, it can be used to monitor the HTTP(s) traffic activity between the client and web service through a progress update delegate. Overall, the library is highly customizable, including the following configurable parameters:
The library is tested and working in iOS 7 and above. Older version may work but it is not explicitly tested. It only requires Foundation.framework that is probably included in any iOS project.
You may need the latest developer tools in order to build the demo project and run the tests.
While creating files for HTTP(s) requests, the recorder uses
NSFileProtectionKey attribute to improve the file security. It is a generic library that is designed to record and monitor traffic activity, however, each app may apply its own discretion over what to record and monitor based on its own policy and regulation.
The project is in its early stage. We are intending to apply it to different projects both internally and externally, and fix any issues that are found. In addition, we are going to continue to improve it as the following:
If you want to help with any of the above or have any other ideas over how to enhance it or fix a bug, pull requests/new issues/comments/questions are highly welcome.
We welcome your interest in Capital One’s Open Source Projects. Any contributor to this project must accept and sign a Capital One Contributor Licensing Agreement (CLA). Except for the license granted in this agreement to Capital One and to recipients of software distributed by Capital One, you reserve all right, title, and interest in and to your contributions; this agreement does not impact your rights to use your own contributions for any other purpose.