
[![Windows](https://github.com/Corion/HTTP-Request-Diff/workflows/windows/badge.svg)](https://github.com/Corion/HTTP-Request-Diff/actions?query=workflow%3Awindows)
[![MacOS](https://github.com/Corion/HTTP-Request-Diff/workflows/macos/badge.svg)](https://github.com/Corion/HTTP-Request-Diff/actions?query=workflow%3Amacos)
[![Linux](https://github.com/Corion/HTTP-Request-Diff/workflows/linux/badge.svg)](https://github.com/Corion/HTTP-Request-Diff/actions?query=workflow%3Alinux)

# NAME

HTTP::Request::Diff - create diffs between HTTP requests

# SYNOPSIS

    use HTTP::Request::Common 'GET';

    my $diff = HTTP::Request::Diff->new(
        reference => GET('https://example.com/?foo=bar' ),
        #actual    => $req2,
        skip_headers => \@skip,
        ignore_headers => \@skip2,
        mode => 'exact', # default is 'semantic'
    );

    my @differences = $diff->diff( GET('https://example.com/' ));
    say Dumper $differences[0];
    # {
    #   'kind' => 'value',
    #   'type' => 'query.foo',
    #   'reference' => [
    #                    'bar'
    #                  ],
    #   'actual' => [
    #                 undef
    #               ]
    # }
    #

    say $diff->as_table(@differences);
    # +-----------+-----------+-----------+
    # | Type      | Reference | Actual    |
    # +-----------+-----------+-----------+
    # | query.foo | bar       | <missing> |
    # +-----------+-----------+-----------+

# METHODS

## `->new`

    my $diff = HTTP::Request::Diff->new(
        mode => 'semantic',
    );

### Options

- `mode`

        mode => 'strict',

    The comparison mode. The default is semantic comparison, which considers some
    differences insignificant:

    - The order of HTTP headers
    - The boundary strings of multipart POST requests
    - The order of query parameters
    - The order of form parameters
    - A `Content-Length: 0` header is equivalent to a missing `Content-Length` header

    `strict` mode wants the requests to be as identical as possible.
    `lax` mode considers query parameters in the POST body as equivalent.

- `reference`

    (optional) The reference request to compare against. Alternatively pass in
    the request in the call to `->diff`.

- `skip_headers`

        skip_headers => ['X-Proxied-For'],

    List of headers to skip when comparing. Missing headers are not significant.

- `ignore_headers`

        ignore_headers => ['Accept-Encoding'],

    List of headers to ignore when comparing. Missing headers are significant.

- `canonicalize`

    Callback to canonicalize a request. The request will be passed in unmodified
    either as a string or a [HTTP::Request](https://metacpan.org/pod/HTTP%3A%3ARequest).

- `compare`

    Arrayref of things to compare.

- `warn_on_newlines`

    (optional) If we should output warnings when we receive ` \n ` delimited input
    instead of ` \r\n `. This mostly happens when input is read from text files
    for regression test.

    Default is true.

## `->diff`

    my @diff = $diff->diff( $reference, $actual, %options );
    my @diff = $diff->diff( $actual, %options );

Performs the diff and returns an array of hashrefs with differences.

## `->as_table( @diff )`

    my @diff = $diff->diff( $request1, $request2 );
    print $diff->as_table( @diff );
    # +-----------------+-----------+--------+
    # | Type            | Reference | Actual |
    # +-----------------+-----------+--------+
    # | request.content | Ümloud    | Umloud |
    # +-----------------+-----------+--------+

Renders a diff as a table, using [Term::Table](https://metacpan.org/pod/Term%3A%3ATable).

# REPOSITORY

The public repository of this module is
[https://github.com/Corion/HTTP-Request-Diff](https://github.com/Corion/HTTP-Request-Diff).

# SUPPORT

The public support forum of this module is [https://perlmonks.org/](https://perlmonks.org/).

# BUG TRACKER

Please report bugs in this module via the Github bug queue at
[https://github.com/Corion/HTTP-Request-Diff/issues](https://github.com/Corion/HTTP-Request-Diff/issues)

# AUTHOR

Max Maischein `corion@cpan.org`

# COPYRIGHT (c)

Copyright 2023- by Max Maischein `corion@cpan.org`.

# LICENSE

This module is released under the Artistic License 2.0.
