TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Mar 2015 |
Maintained by Kevin Harwood.
Depends on: | |
AFNetworking | ~> 2.1 |
AFNetworking/NSURLSession | ~> 2.1 |
An AFNetworking extension to automatically generate a HTTP Archive file of all of your network requests!
What is HTTP Archiving (HAR)? It's a specification that allows you to store HTTP request/responses as well as meta data, and view that information at a later time to help with debugging.
You can find the HAR specification here, and you can find an online HAR viewer here. You can download a sample HAR log from here and drag it into the online viewer to take a look.
There is also a long list of tools that support the HAR format here.
The full spec has not been fully implemented yet, but basic timing information has been included. By releasing this to the community, we are hopeful more advanced logging data will be implemented.
Using a HARchiver is as simple as creating an instance of it, and telling it to start. The archiver will archive requests as they come in directly to disk at the path you specify.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"log.har"];
self.afArchiver = [[AFHARchiver alloc] initWithPath:filePath error:nil];
[self.afArchiver startArchiving];
You will most likely run into a scenario where you only want to archive specific operations. The most common use has been to ignore logging image files to prevent your archive from growing too large in size. For AFHTTPRequestOperations, you can use setShouldArchiveOperationBlock:. For NSURLSessionTasks, you can use setShouldArchiveTaskBlock:.
[self.afArchiver
setShouldArchiveOperationBlock:^BOOL(AFHTTPRequestOperation *operation) {
return [operation.responseSerializer isKindOfClass:[AFJSONResponseSerializer class]];
}];
[self.afArchiver
setShouldArchiveTaskBlock:^BOOL(NSURLSessionTask *task, id<AFURLResponseSerialization> responseSerializer, id serializedResponse) {
return [(NSObject*)responseSerializer isKindOfClass:[AFJSONResponseSerializer class]];
}];
}];
If your application is using AFNetworking 2.0.0, targeting iOS 6, and using the NSURLConnection API's, continue to use AFHARchiver 0.1.0. The current version of AFHARchiver requires the AF/NSURLSession API's included in AFNetworking 2.0.0.
There is some advanced functionality that has not yet been implemented that will lead to more advanced logs. These include the following:
Created by Kevin Harwood (Email | Twitter) at Mutual Mobile.
AFHARchiver is available under the MIT license. See the LICENSE file for more info