Coder Social home page Coder Social logo

wessmith / afharchiver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mutualmobile/afharchiver

0.0 1.0 1.0 536 KB

An AFNetworking extension to automatically generate HTTP Archive files of all of your network requests!

License: MIT License

afharchiver's Introduction

AFHARchiver

An AFNetworking extension to automatically generate a HTTP Archive file of all of your network requests!

Overview

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.

How to use the HARchiver

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];

Archiving Specific AFHTTPRequestOperations / NSURLSessionTasks

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]];
 }];
}];

##Using AFNetworking 2.0.0, iOS 6, and NSURLConnection

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.

A Few TODO's

There is some advanced functionality that has not yet been implemented that will lead to more advanced logs. These include the following:

  • Split the duration of the request into the proper time buckets. Currently all time is passed to the duration bucket.
  • Determine if responses are returning from a local cache using the cache property.
  • Log all cookie information to the cookie property.
  • Calculate the correct headerSize.

Credits

Created by Kevin Harwood (Email | Twitter) at Mutual Mobile.

License

AFHARchiver is available under the MIT license. See the LICENSE file for more info

afharchiver's People

Contributors

kcharwood avatar xueshiqiao avatar

Watchers

James Cloos avatar

Forkers

smup

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.