A PHP library for working with HTTP Archives
Installs: 6 753
Dependents: 0
Suggesters: 0
Security: 0
Stars: 13
Watchers: 3
Forks: 7
Open Issues: 6
Requires
- php: ^8.0
- ext-json: *
- deviantintegral/jms-serializer-uri-handler: ^1.1
- deviantintegral/null-date-time: ^1.0
- doctrine/annotations: ^1.7
- guzzlehttp/psr7: ^2.0
- jms/serializer: ^3.0
- symfony/console: ^5.0||^6.0
- symfony/polyfill-php80: ^1.20
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.13.0
- guzzlehttp/guzzle: ^7.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-29 10:58:40 UTC
README
Requirements
- PHP 8.0+
- The
ext-json
extension.
Installation
composer require deviantintegral/har
, or
download the CLI tool.
Introduction
This library supports reading and writing HTTP Archive files. These archives are JSON objects containing one or more HTTP request and response pairs. In particular, this library is useful for taking HTTP requests exported from a browser's developer tools or with a proxy like mitmproxy and using them as mocks in tests.
Features include:
- Reading a HAR into a fully-typed set of classes.
- Writing a
\Deviantintegral\Har\Har
back out into a HAR JSON string. - Adapters for PSR-7 Request and Response interfaces.
- An interface and
\Deviantintegral\Har\HarRepository
class to load HARs from a filesystem or other backend. - A CLI tool to split a HAR file into single files per request / response pair.
Example
See ReadmeTest.php for an example of how to use this library.
Optional values
The HAR specification documents some fields as -1
if they do not have a
value. Other fields, like comment
, may be omitted.
Fields that may be omitted will have a has
method that should be called
before calling get
. For integer fields, the return value must be checked for
-1
.
Fidelity of Serialized and Deserialized data
This library aims to preserve the actual JSON representation of loaded objects. However, in some cases, this is not possible. In particular, PHP only supports up to 6 digits in ISO 8601 timestamps, so any additional precision is lost. See HarTest for an example that checks the reading and writing of a HAR.