GithubHelp home page GithubHelp logo

harparser's Introduction

HAR Parser

Latest Version Software license Build Status Quality Grade Total Downloads

Library to parse and generate HAR file format.

Usage

Load you HAR file with an Parser object or with Log entity.

With Parser class:

use ElGigi\HarParser\Parser;

$harFile = new Parser();

$log = $harFile->parse('/path/of/my/file.har', contentIsFile: true);
$log = $harFile->parse(['my' => 'har decoded']);

With Log entity class:

use ElGigi\HarParser\Entities\Log;

$log = Log::load(json_decode(file_get_contents('/path/of/my/file.har'), true));

Entities

The HAR file is distributed in several entities:

  • Log
    • Creator
    • Browser
    • Page[]
      • PageTimings
    • Entry[]
      • Request
        • Cookie[]
        • Header[]
        • PostData
      • Response
        • Cookie[]
        • Header[]
        • Content
      • Timings

Builder

Two builders are available to construct an HAR file from entities:

  • Builder: build a Log entity from others entities
  • BuilderStream: build directly the JSON file in stream to prevent memory usage

Both implements BuilderInterface:

  • BuilderInterface::reset(): void: reset builder data
  • BuilderInterface::setVersion(string $version): void: define version of HAR file (default: 1.2)
  • BuilderInterface::setCreator(string $creator): void: set creator entity
  • BuilderInterface::setBrowser(string $browser): void: set browser entity
  • BuilderInterface::addPage(Page ...$page): void: add a page entity (or multiple pages)
  • BuilderInterface::addEntry(Entry ...$entry): void: add an entry entity (or multiple entries)
  • BuilderInterface::setComment(?string $comment): void: define comment of HAR file

For stream builder, the constructor attempt a valid resource (writeable and seekable).

For standard builder, the constructor accept an HAR file, for example, complete an existent HAR.

Anonymize HAR

In some cases, like unit tests, you need to anonymize your HAR file.

The Anonymizer class it's do for that!

class Anonymizer
{
    /**
     * Add header to redact.
     *
     * @param string ...$regex
     *
     * @return void
     */
    public function addHeaderToRedact(string ...$regex): void;

    /**
     * Add query string to redact.
     *
     * @param string ...$regex
     *
     * @return void
     */
    public function addQueryStringToRedact(string ...$regex): void;

    /**
     * Add post data to redact.
     *
     * @param string ...$regex
     *
     * @return void
     */
    public function addPostDataToRedact(string ...$regex): void;

    /**
     * Add accepted mime.
     *
     * @param string ...$mime
     *
     * @return void
     */
    public function addAcceptedMime(string ...$mime): void;

    /**
     * Add content to redact.
     *
     * @param array $regexes
     *
     * @return void
     */
    public function addContentToRedact(array $regexes): void;

    /**
     * Add callback.
     *
     * @param callable ...$callback
     *
     * @return void
     */
    public function addCallback(callable ...$callback): void;

    /**
     * Anonymize HAR file.
     *
     * @param Log $log
     *
     * @return Log
     * @throws InvalidArgumentException
     */
    public function anonymize(Log $log): Log;
}

harparser's People

Contributors

elgigi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.