{"id":21333131,"url":"https://github.com/elgigi/harparser","last_synced_at":"2025-07-12T10:31:59.887Z","repository":{"id":56976659,"uuid":"387922543","full_name":"ElGigi/HarParser","owner":"ElGigi","description":"Library to parse and generate HAR file format.","archived":false,"fork":false,"pushed_at":"2024-03-22T11:54:49.000Z","size":595,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-29T00:57:34.783Z","etag":null,"topics":["har","http","http-logs","log","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ElGigi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-20T21:54:45.000Z","updated_at":"2024-02-18T18:06:00.000Z","dependencies_parsed_at":"2023-02-01T02:30:46.235Z","dependency_job_id":null,"html_url":"https://github.com/ElGigi/HarParser","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElGigi%2FHarParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElGigi%2FHarParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElGigi%2FHarParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElGigi%2FHarParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ElGigi","download_url":"https://codeload.github.com/ElGigi/HarParser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225814707,"owners_count":17528295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["har","http","http-logs","log","php"],"created_at":"2024-11-21T22:54:45.114Z","updated_at":"2024-11-21T22:54:45.652Z","avatar_url":"https://github.com/ElGigi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HAR Parser\n\n[![Latest Version](https://img.shields.io/packagist/v/elgigi/har-parser.svg?style=flat-square)](https://github.com/ElGigi/HarParser/releases)\n[![Software license](https://img.shields.io/github/license/ElGigi/HarParser.svg?style=flat-square)](https://github.com/ElGigi/HarParser/blob/main/LICENSE)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/ElGigi/HarParser/tests.yml?branch=main\u0026style=flat-square)](https://github.com/ElGigi/HarParser/actions/workflows/tests.yml?query=branch%3Amain)\n[![Quality Grade](https://img.shields.io/codacy/grade/0447a4290de744dc81a7e2cf9891a47d/main.svg?style=flat-square)](https://app.codacy.com/gh/ElGigi/HarParser)\n[![Total Downloads](https://img.shields.io/packagist/dt/elgigi/har-parser.svg?style=flat-square)](https://packagist.org/packages/elgigi/har-parser)\n\nLibrary to parse and generate [HAR file format](https://en.wikipedia.org/wiki/HAR_(file_format)).\n\n## Usage\n\nLoad you HAR file with an `Parser` object or with `Log` entity.\n\nWith `Parser` class:\n\n```php\nuse ElGigi\\HarParser\\Parser;\n\n$harFile = new Parser();\n\n$log = $harFile-\u003eparse('/path/of/my/file.har', contentIsFile: true);\n$log = $harFile-\u003eparse(['my' =\u003e 'har decoded']);\n```\n\nWith `Log` entity class:\n\n```php\nuse ElGigi\\HarParser\\Entities\\Log;\n\n$log = Log::load(json_decode(file_get_contents('/path/of/my/file.har'), true));\n```\n\n## Entities\n\nThe HAR file is distributed in several entities:\n\n- Log\n    - Creator\n    - Browser\n    - Page[]\n        - PageTimings\n    - Entry[]\n        - Request\n            - Cookie[]\n            - Header[]\n            - PostData\n        - Response\n            - Cookie[]\n            - Header[]\n            - Content\n        - Timings\n\n## Builder\n\nTwo builders are available to construct an HAR file from entities:\n\n- `Builder`: build a `Log` entity from others entities\n- `BuilderStream`: build directly the JSON file in stream to prevent memory usage\n\nBoth implements `BuilderInterface`:\n\n- `BuilderInterface::reset(): void`: reset builder data\n- `BuilderInterface::setVersion(string $version): void`: define version of HAR file (default: 1.2)\n- `BuilderInterface::setCreator(string $creator): void`: set creator entity\n- `BuilderInterface::setBrowser(string $browser): void`: set browser entity\n- `BuilderInterface::addPage(Page ...$page): void`: add a page entity (or multiple pages)\n- `BuilderInterface::addEntry(Entry ...$entry): void`: add an entry entity (or multiple entries)\n- `BuilderInterface::setComment(?string $comment): void`: define comment of HAR file\n\nFor stream builder, the constructor attempt a valid resource (writeable and seekable).\n\nFor standard builder, the constructor accept an HAR file, for example, complete an existent HAR.\n\n## Anonymize HAR\n\nIn some cases, like unit tests, you need to anonymize your HAR file.\n\nThe `Anonymizer` class it's do for that!\n\n```php\nclass Anonymizer\n{\n    /**\n     * Add header to redact.\n     *\n     * @param string ...$regex\n     *\n     * @return void\n     */\n    public function addHeaderToRedact(string ...$regex): void;\n\n    /**\n     * Add query string to redact.\n     *\n     * @param string ...$regex\n     *\n     * @return void\n     */\n    public function addQueryStringToRedact(string ...$regex): void;\n\n    /**\n     * Add post data to redact.\n     *\n     * @param string ...$regex\n     *\n     * @return void\n     */\n    public function addPostDataToRedact(string ...$regex): void;\n\n    /**\n     * Add accepted mime.\n     *\n     * @param string ...$mime\n     *\n     * @return void\n     */\n    public function addAcceptedMime(string ...$mime): void;\n\n    /**\n     * Add content to redact.\n     *\n     * @param array $regexes\n     *\n     * @return void\n     */\n    public function addContentToRedact(array $regexes): void;\n\n    /**\n     * Add callback.\n     *\n     * @param callable ...$callback\n     *\n     * @return void\n     */\n    public function addCallback(callable ...$callback): void;\n\n    /**\n     * Anonymize HAR file.\n     *\n     * @param Log $log\n     *\n     * @return Log\n     * @throws InvalidArgumentException\n     */\n    public function anonymize(Log $log): Log;\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felgigi%2Fharparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felgigi%2Fharparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felgigi%2Fharparser/lists"}