sub compareHeaderValues()

in tools/compare_servers.pl [76:126]


sub compareHeaderValues($$)
{
    my ($response1, $response2) = @_;

    my @test_headers =
      qw(ETag Cache-Control Connection Accept-Ranges Server Content-Type Access-Control-Allow-Methods Access-Control-Allow-Origin Strict-Transport-Security);
    my $return_val = 0;    # header value match

    if ($verbose >= 3) {
        foreach my $field ($response1->header_field_names) {
            print "\t\t\t~ " . $field . ": " . $response1->header($field) . "\n";
        }

        print "\t\tHost2: \n";

        foreach my $field ($response2->header_field_names) {
            print "\t\t\t~ " . $field . ": " . $response2->header($field) . "\n";
        }
    }

    # Test specific headers that are defined above
    foreach my $field (@test_headers) {
        my $value1 = $response1->header($field);
        my $value2 = $response2->header($field);

        if (defined $value1 && defined $value2) {
            if ($value1 ne $value2) {
                print "\t\t- $field: $value1 ne $value2\n" if $verbose;
                print "\t\t\t - Via host1: " . $response1->header('Via') . " host2: " . $response2->header('Via') . "\n"
                  if $verbose;
                print "\t\t\t - Last-Modified host1: "
                  . $response1->header('Last-Modified')
                  . " host2: "
                  . $response2->header('Last-Modified') . "\n"
                  if $verbose;
                if (defined $response2->header('Content-Encoding')) {
                    print "\t\t\t - Content-Encoding host1: "
                      . $response1->header('Content-Encoding')
                      . " host2: "
                      . $response2->header('Content-Encoding') . "\n";
                } else {
                    print "\t\t\t - Content-Encoding host1: " . $response1->header('Content-Encoding') . " host2: ''\n";
                }
                $return_val = 1;
            } else {
                print "\t\t- $field: $value1 eq $value2\n" if $verbose >= 2;
            }
        }
    }
    return $return_val;
}