Home

Awesome

Capital One built this project to help our engineers as well as users in the community. We are no longer able to fully support the project. We have archived the project as of Jul 27 2019 where it will be available in a read-only state. Feel free to fork the project and maintain your own version.

SWHttpTrafficRecorder Build Status

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.

Setup

Integrating in Your Project

CocoaPods

The recommended way to add SWHttpTrafficRecorder to your project. Add SWHttpTrafficRecorder to your Podfile:

pod 'SWHttpTrafficRecorder'
Carthage

Add this repo to your Cartfile:

github "capitalone/SWHttpTrafficRecorder"
Manual

Or since the library contains only two files (SWHttpTrafficRecorder.h and SWHttpTrafficRecorder.m), you can just drop them anywhere in your project and it is done.

Getting Started

Even though the library is highly customizable, you can get started just by inserting one line of code.

Objective C:
[[SWHttpTrafficRecorder sharedRecorder] startRecording];
Swift:
SWHttpTrafficRecorder.sharedRecorder().startRecording()

Note: NSURLConnection and 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.

Features

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:

Requirements

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.

Security Consideration

While creating files for HTTP(s) requests, the recorder uses NSFileProtectionComplete for 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.

Roadmap

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:

  1. Create a testing suite for regression to make sure future contributions do not break existing functionalities;
  2. Provide more documentation and sample code through wiki page.

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.

Contributions

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.

Link to CLA